Jump to content

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-

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.