I think I solved, or worked around, the problem. It's all in the math! My original code:
PHP Code:
function createthumb($name,$filename,$max_w,$max_h){ $src_img=imagecreatefromjpeg("../images/".$name);
$width=imageSX($src_img); $heigth=imageSY($src_img);
$x_ratio= $max_w / $width; $y_ratio= $max_h / $heigth;
if (($width <= $max_w) && ($heigth <= $max_h)){ $tn_width = $width; $tn_heigth = $heigth; } else{ $tn_width = ceil($x_ratio * $width); $tn_heigth = $max_h; }
$dst_image = ImageCreateTrueColor($tn_width,$tn_heigth); imagecopyresampled($dst_image,$src_img,0,0,0,0,$tn_width,$tn_heigth,$width,$heigth); imagejpeg($dst_image,$filename,100); imagedestroy($src_img); imagedestroy($dst_image); }
This set the max heigth at a solid number no matter what the original image was. A simple change so to use the ratio for resize seems to have fixed it.
PHP Code:
$tn_heigth = ceil($y_ratio * $heigth);
I had simply done a paste of a snippet to do this and now see that the original was flawed just slightly and that caused major confusion on my part.
Last edited by alhefner; 10-01-2008 at 12:21 AM..
Reason: typo
|