scraptoft Posted June 26, 2006 Share Posted June 26, 2006 Hi, Can I change my thumbnail creator script to resize the thumbnails to [b]exact sizes[/b]? As it is it creates the thumbnail by percentage of width and height(?).Here is my code:[code] //get the dimensions for the thumbnail $thumb_width = $width * 0.30; $thumb_height = $height * 0.30; //create the thumbnail $largeimage = imagecreatefromjpeg($newfilename); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); imagejpeg($thumb, $newthumbname); imagedestroy($largeimage); imagedestroy($thumb);[/code]Any suggestions on how to do this? I would like all of my thumbnails creating to 55x55 pixels.Cheers Link to comment https://forums.phpfreaks.com/topic/12950-thumbnail-resizing-to-exact-size/ Share on other sites More sharing options...
litebearer Posted June 26, 2006 Share Posted June 26, 2006 This might help...[a href=\"http://www.nstoia.com/toh/technical/imageresize/\" target=\"_blank\"]http://www.nstoia.com/toh/technical/imageresize/[/a]Lite... Link to comment https://forums.phpfreaks.com/topic/12950-thumbnail-resizing-to-exact-size/#findComment-49769 Share on other sites More sharing options...
scraptoft Posted June 26, 2006 Author Share Posted June 26, 2006 Thanks for the link, here is what I have came up with so far:[code] //"convert" the image to jpg $maxwidth = 100; $maxheight = 400; if (($width>$maxwidth) OR ($height>$maxheight)) ( $image_jpg = imagecreatetruecolor($width, $height); imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $maxwidth, $maxheight, $maxwidth, $maxheight); )else ( $image_jpg = imagecreatetruecolor($width, $height); imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);) imagejpeg($image_jpg, $newfilename); imagedestroy($image_old); imagedestroy($image_jpg); }[/code]I'm getting a Parse error: syntax error, unexpected ';' . Anyone see why? Link to comment https://forums.phpfreaks.com/topic/12950-thumbnail-resizing-to-exact-size/#findComment-49797 Share on other sites More sharing options...
redarrow Posted June 26, 2006 Share Posted June 26, 2006 try this ok.[code] //"convert" the image to jpg$maxwidth = 100;$maxheight = 400;if (($width>$maxwidth) OR ($height>$maxheight)) {$image_jpg = imagecreatetruecolor($width, $height);imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $maxwidth, $maxheight, $maxwidth, $maxheight); }else{$image_jpg = imagecreatetruecolor($width, $height);imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);(imagejpeg($image_jpg, $newfilename);imagedestroy($image_old);imagedestroy($image_jpg); }[/code] Link to comment https://forums.phpfreaks.com/topic/12950-thumbnail-resizing-to-exact-size/#findComment-49807 Share on other sites More sharing options...
scraptoft Posted June 27, 2006 Author Share Posted June 27, 2006 I'm getting a Parse error: syntax error, unexpected $end. But can't find any curly brackets that havn't been closed. I'm hoping its only somthing minor. Link to comment https://forums.phpfreaks.com/topic/12950-thumbnail-resizing-to-exact-size/#findComment-50059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.