The following function is what I am using. For some reason it will return the recalculated image width but it will not return the recalculated image height.
But when I pull the code out of the function and use it in any place I need to change an images displayed size, it works fine.
This has me baffled, why would the exact same code work in one place but not another?
the function
function ChangeImageSize($image, $directory, $width) {
if ((isset($image)) && ($image != '')) {
$photo = $directory . '/' . $image;
$imagesize = getimagesize($photo);
if ($imagesize[0]> $width) {
$widthfrac = ($width / $imagesize[0]);
$imagewidth = ($widthfrac * $imagesize[0]);
$imageheight = ($widthfrac * $imagesize[1]);
}
else {
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
}
}
else {
$photo = 'http://www.mysite.com/images/default.gif';
$imagewidth = 180;
$imageheight = 150;
}
return array($photo, $imagewidth, $imageheight);
}
a line that calls the function
list($map_image, $map_width, $map_hieght) = ($Route_Map != '') ? ChangeImageSize($Route_Map, 'maps', '520'): '';