Thumbnail Creation of An Image from a directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lostinphp
Forum Commoner
Posts: 44
Joined: Wed Jul 27, 2005 5:10 am
Location: Paris,France.

Thumbnail Creation of An Image from a directory

Post by lostinphp »

Is there anyone who can help me with a minor problem..i have a folder with large images that gets uploaded from a form.i have a thumb folder where thumbnail images of the images from the large folder gets automatically generated.the problem is that the thumbnail image created is nothing but a block of black color.i guess the problem is wid the imagetruecolor option which is not working even wid gd library installed in the project.
so please give your suggestion as to how i can conserve the color of the thumbnail images.
any kind of help will be really helpful.thank u
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

For jpeg, I use these functions in the following order and it works.

imagecreatefromjpeg
imagecreatetruecolor
imagecopyresized
imagejpeg
lostinphp
Forum Commoner
Posts: 44
Joined: Wed Jul 27, 2005 5:10 am
Location: Paris,France.

help!

Post by lostinphp »

thank u but i have used the same thing but it still doesnt work and im still generating black blocks instead of the thumbnail version of the original images.
help!
if($ftype=="image/jpeg"){

$im=ImageCreateFromJPEG($fname);

$width=ImageSx($im); // Original picture width is stored

$height=ImageSy($im); // Original picture height is stored

$newimage=@ImageCreateTrueColor($n_width,$n_height);

ImageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);

ImageJPEG($newimage,$tsrc);

chmod("$tsrc",0777);

}}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Check your width variables. If any of them are zero, you'll get a black image. Also, use imagecopyresampled() rather than imagecopyresized() if you've got GD 2.0 - it makes much smoother thumbnails.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply