Yep your correct, but doesn't seem to work when you want to go up a level. It always seems to use the same directory from the original image file.
I'm sure the change is here, but I'm not any good at php.
// Path to mini photo
$p_dir = dirname(($p = strpos($file, '://')) ? substr($file, strpos($file, '/', $p + 3) + 1) : ($file{0} == '/' ? substr($file, 1) : $file)).'/';
$p_img = $p_dir.basename($file);
$mp_dir = $p_dir.$dir;
$mp_img = $mp_dir.basename($file);
if (file_exists($modx->config['base_path'].$mp_img)) {
return '/'.$mp_img;
}