Schlo_50 Posted November 12, 2008 Share Posted November 12, 2008 Hi all, Firstly, I am in no way knowledgeable about php's image functions and have tried to research this for so long now, hence why I am here so thanks for any help given! I have a large image that I've uploaded into a folder (uploads) on my server and I would like to generate a thumbnail of it keeping aspect ratio and store it in another folder. (thumbs) My code so far generates a thumbnail in the correct folder but it seems to crop the original image rather than resize it.. The thumbnails need to be as close to 150px x 150px as possible. function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth) { $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName"); $origWidth = imagesx($srcImg); $origHeight = imagesy($srcImg); $ratio = $origWidth / $thumbWidth; $thumbHeight = $origHeight * $ratio; $thumbImg = imagecreate($thumbWidth, $ratio); imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbImg), imagesy($thumbImg)); imagejpeg($thumbImg, "$thumbDirectory/$imageName"); } createThumbnail("uploads", "".$product_to_update.".jpg", "thumbs/", 150); Thanks guys, Quote Link to comment https://forums.phpfreaks.com/topic/132445-image-resizing-problems/ Share on other sites More sharing options...
premiso Posted November 12, 2008 Share Posted November 12, 2008 http://www.4wordsystems.com/php_image_resize.php May help you on your way. =) Google is a developers best tool IMO. Quote Link to comment https://forums.phpfreaks.com/topic/132445-image-resizing-problems/#findComment-688600 Share on other sites More sharing options...
Schlo_50 Posted November 13, 2008 Author Share Posted November 13, 2008 Thanks for the link. I've already been there though! lol Is there nothign onviously wrong with my code though? I'd like to get what I have at the moment working ideally. Quote Link to comment https://forums.phpfreaks.com/topic/132445-image-resizing-problems/#findComment-689192 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.