ttmt Posted March 25, 2011 Share Posted March 25, 2011 Proportionally scale image - imagecopyresampled() This is part of a function I have to upload images and create thumbnails from the stored image - '$stored_image' $src_image = imagecreatefromjpeg($stored_image); // $src_width = imagesx($src_image); $src_height = imagesy($src_image); $new_width = 85; $new_height = 85; // if($src_width > $src_height){ $thumb_w = $new_width; $thumb_h = $src_height*($new_height/$src_width); } if($src_width < $src_height){ $thumb_w = $src_width*($new_width/$src_height); $thumb_h = $new_height; } if($src_width == $src_height){ $thumb_w = $new_width; $thumb_h = $new_height; } // $thumb = imagecreatetruecolor($thumb_w, $thumb_h); imagecopyresampled($thumb, $src_image,0,0,0,0,$thumb_w, $thumb_h, $src_width, $src_height); imagejpeg($thumb, $stored_thumb, 100); imagedestroy($src_image); imagedestroy($thumb); }else{ The images are different size and orientations, landscape and portrait. The thumbnails need to have the same height so I need to proportionally scale the images How can I proportionally scale images so the thumbnails have the same height I'm really stuck here so any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/231674-proportionally-scale-image-imagecopyresampled/ Share on other sites More sharing options...
floridaflatlander Posted March 25, 2011 Share Posted March 25, 2011 I'm almost sure it's a math problem that would be adjusted for each photo, as a temp fix and if you need 90px in height on the dot right now you can make your width wider than needed to make sure 90px is the height all the time. My work day is starting and so I'll come back and play with this later. Quote Link to comment https://forums.phpfreaks.com/topic/231674-proportionally-scale-image-imagecopyresampled/#findComment-1192118 Share on other sites More sharing options...
gojo62 Posted March 28, 2011 Share Posted March 28, 2011 $max = 100; $newwidth = $max / $height * $width; $newheight = $max; hope that helps Gary Quote Link to comment https://forums.phpfreaks.com/topic/231674-proportionally-scale-image-imagecopyresampled/#findComment-1193172 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.