Jump to content

Function to Create Thumbnail


aquanova27

Recommended Posts

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

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-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.