Russia Posted November 23, 2014 Share Posted November 23, 2014 Hey guys I have a small issue, i have an upload that resizes the image into thumbnail by max width and ratios the width based on that.Here is my code $width = 100; //*** Set a Fix Width & Height (Auto caculate) ***// $size = GetimageSize($images); $height = round($width * $size[1] / $size[0]); $images_orig = imagecreatefromjpeg($images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width + 1, $height + 1, $photoX, $photoY); ImageJPEG($images_fin, $new_images); What I am wanting to do is instead upload the image with a max height and ratio the width proportionally. What variables do I have to reverse? Link to comment https://forums.phpfreaks.com/topic/292651-auto-adjust-width-image-creation-but-set-height/ Share on other sites More sharing options...
QuickOldCar Posted November 23, 2014 Share Posted November 23, 2014 With this you can set a max width or height and will be a pretty close scale <?php $max_size = 100; $size = getimagesize($images); $ratio = $size[0] / $size[1]; if ($ratio >= 1) { $width = $max_size; $height = round($max_size / $ratio); } else { $width = round($max_size * $ratio); $height = $max_size; } $images_orig = imagecreatefromjpeg($images); $photoX = ImagesX($images_orig); $photoY = ImagesY($images_orig); $images_fin = ImageCreateTrueColor($width, $height); ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width, $height, $photoX, $photoY); ImageJPEG($images_fin, $new_images); imagedestroy($images_fin); //you should destroy at the end because will reside in memory ?> Link to comment https://forums.phpfreaks.com/topic/292651-auto-adjust-width-image-creation-but-set-height/#findComment-1497367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.