aquanova27 Posted August 13, 2007 Share Posted August 13, 2007 Hello, I'm trying to create a function to create thumbnail. Since I'm new to this gd and OOP stuff, I browsed for the coding and turned it into a function. The thumbnail was working fine. But, why can't I create two thumbnails after one another? It only displayed one thumbnail. Is it the way I use the function? mythumb('../photo/IMG_5929.JPG'); mythumb('../photo/IMG_5928.JPG'); Thank you for any kind of help... -aQuanova- <?php function mythumb($myphoto){ // Set crop dimensions. $width = 100; $height = 100; // Existing Image Dimension $dimensions = getimagesize($myphoto); // The canvas $canvas = imagecreatetruecolor($width,$height); $piece = imagecreatefromjpeg($myphoto); // Prepare image resizing and crop -- Center crop location $newwidth = $dimensions[0] / 2; $newheight = $dimensions[1] / 2; $cropLeft = ($newwidth/2) - ($width/2); $cropHeight = ($newheight/2) - ($height/2); // Generate the cropped image imagecopyresized($canvas, $piece, 0,0, $cropLeft, $cropHeight, $width, $height, $newwidth, $newheight); // Display it header('Content-Type: image/jpeg'); imagejpeg($canvas); // Clean-up imagedestroy($canvas); imagedestroy($piece); } mythumb('../photo/IMG_5929.JPG'); mythumb('../photo/IMG_5928.JPG'); ?> Link to comment https://forums.phpfreaks.com/topic/64657-function-to-create-thumbnail/ Share on other sites More sharing options...
dbo Posted August 13, 2007 Share Posted August 13, 2007 This code sends a header that tells it to act like an image after it has recreated it. Because of this you can't display two on the same page. Link to comment https://forums.phpfreaks.com/topic/64657-function-to-create-thumbnail/#findComment-322371 Share on other sites More sharing options...
aquanova27 Posted August 14, 2007 Author Share Posted August 14, 2007 thanks dbo I guess "header('Content-Type: image/jpeg');" is needed to display the jpeg.. So what should I do then? Put it outside the function was not working as well.. Can anybody please suggest what should I do? Really thank you for any help =) -aQuanova- Link to comment https://forums.phpfreaks.com/topic/64657-function-to-create-thumbnail/#findComment-323518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.