not sure i followed everyhting (friday), but in my country we do it like:
function scale_image($p,$mw='',$mh='', $alt='image', $brd=0) { // path, max_width, max_height, (source php.net)
if(list($w,$h) = @getimagesize($p)) {
$wh = @getimagesize($p);
foreach(array('w','h') as $v) {
$m = "m {$v}";
if($ {$v} > $ {$m} && $ {$m}) {
$o = ($v == 'w') ? 'h' : 'w';
$r = $ {$m} / $ {$v}; $ {$v} = $ {$m}; $ {$o} = ceil($ {$o} * $r);
}
}
return array("<img src=' {$p}' alt=' {$alt}' width=' {$w}' height=' {$h}' border=' {$brd}'/>", $wh[0], $wh[1]);
}
}
then again I might not be in the right country!