atholon Posted August 18, 2008 Share Posted August 18, 2008 Hi there, I am trying to figure out the best way to crop any image (with differing dimensions) to the same size without distorting it. My target thumbnail size would be 110 x 110. Any ideas? Link to comment https://forums.phpfreaks.com/topic/120272-best-cropping-method/ Share on other sites More sharing options...
lemmin Posted August 18, 2008 Share Posted August 18, 2008 Here is part of a script I made awhile ago that will resize to a max width or height (depending on the layout of the image) and keep the ratio: <?php $maxWidth = 300; $maxHeight = 225; move_uploaded_file($_FILES['upfile']['tmp_name'], "images/".$_FILES['upfile']['name']); $imgSize = getimagesize("images/".$_FILES['upfile']['name']); if ($imgSize[0] > $maxWidth && $imgSize[0] > $imgSize[1]) { $newWidth = $maxWidth; $newHeight = ($maxWidth/$imgSize[0])*$imgSize[1]; } else if ($imgSize[1] > $maxHeight) { $newWidth = ($maxHeight/$imgSize[1])*$imgSize[0]; $newHeight = $maxHeight; } else { $newWidth = $imgSize[0]; $newHeight = $imgSize[1]; } ?> Link to comment https://forums.phpfreaks.com/topic/120272-best-cropping-method/#findComment-619632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.