[PHP] problems with thumbnail image
hello, I am a newbie trying to create on the fly thumbnail images on a debian sarge system with PHP Version 4.3.9-1. The following code is used ? function thumbnail_img($photo_img_name) { $percent = 0.5; list($width, $height) = getimagesize($photo_img_name); $newwidth = $width * $percent; $newheight = $height * $percent; $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefrompng($photo_img_name); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); return imagepng($thumb); } print 'HTML'; print 'HEAD'; print 'META HTTP-EQUIV=Pragma CONTENT=no-cache'; print 'TITLEImage/TITLE'; print '/HEAD'; print 'body'; //image file name $photo_img_name='./photos/1.png'; //display original image print 'IMG SRC='.$photo_img_name.' border=1'; //thumbnail image print 'IMG SRC='.thumbnail_img($photo_img_name).' border=1'; print '/body'; print '/html'; ? The original image gets displayed correctly. But in place of the thumbnail image i get loads of junk text data. I guess the hmtl tags are all in order as the original image is perfectly displayed. What have i missed. Any comments, help etc will be appreciated. regards Punit Neb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problems with thumbnail image
2007. 03. 2, péntek keltezéssel 13.56-kor Punit Neb ezt írta: hello, I am a newbie trying to create on the fly thumbnail images on a debian sarge system with PHP Version 4.3.9-1. The following code is used ? function thumbnail_img($photo_img_name) { $percent = 0.5; list($width, $height) = getimagesize($photo_img_name); $newwidth = $width * $percent; $newheight = $height * $percent; $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefrompng($photo_img_name); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); return imagepng($thumb); } print 'HTML'; print 'HEAD'; print 'META HTTP-EQUIV=Pragma CONTENT=no-cache'; print 'TITLEImage/TITLE'; print '/HEAD'; print 'body'; //image file name $photo_img_name='./photos/1.png'; //display original image print 'IMG SRC='.$photo_img_name.' border=1'; //thumbnail image print 'IMG SRC='.thumbnail_img($photo_img_name).' border=1'; print '/body'; print '/html'; ? The original image gets displayed correctly. But in place of the thumbnail image i get loads of junk text data. I guess the hmtl tags are all in order as the original image is perfectly displayed. What have i missed. Any comments, help etc will be appreciated. either create a filename for the thumbnail and add it to the imagepng() call as second parameter and reference it in the thumbnail img tag or put the thumbnail creation in a separate file, say thumbnail.php then the img tag should be like echo img src=\thumbnail.php?img= . $photo_img_name . \; and the thumbnail.php should send out some content-type header e.g. Content-Type: image/png and then call your function like echo thumbnail_img($_GET['img']); hope that helps Zoltán Németh regards Punit Neb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problems with thumbnail image
On Friday 02 March 2007 15:48, Németh Zoltán wrote: Many thanks Németh Zoltán for the prompt response. 2007. 03. 2, péntek keltezéssel 13.56-kor Punit Neb ezt írta: hello, I am a newbie trying to create on the fly thumbnail images on a debian sarge system with PHP Version 4.3.9-1. The following code is used ? function thumbnail_img($photo_img_name) { $percent = 0.5; list($width, $height) = getimagesize($photo_img_name); $newwidth = $width * $percent; $newheight = $height * $percent; $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefrompng($photo_img_name); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); return imagepng($thumb); } print 'HTML'; print 'HEAD'; print 'META HTTP-EQUIV=Pragma CONTENT=no-cache'; print 'TITLEImage/TITLE'; print '/HEAD'; print 'body'; //image file name $photo_img_name='./photos/1.png'; //display original image print 'IMG SRC='.$photo_img_name.' border=1'; //thumbnail image print 'IMG SRC='.thumbnail_img($photo_img_name).' border=1'; print '/body'; print '/html'; ? The original image gets displayed correctly. But in place of the thumbnail image i get loads of junk text data. I guess the hmtl tags are all in order as the original image is perfectly displayed. What have i missed. Any comments, help etc will be appreciated. either create a filename for the thumbnail and add it to the imagepng() call as second parameter and reference it in the thumbnail img tag or put the thumbnail creation in a separate file, say thumbnail.php then the img tag should be like echo img src=\thumbnail.php?img= . $photo_img_name . \; I have used this method for generating the thumbnail images. I avoided creating the thumbnails and saving to the disk as the images change very frequently. Thank you so much for helping me with this one:)) regards Punit Neb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] problems with thumbnail image
On Friday 02 March 2007 21:59, Roberto Mansfield wrote: The problem is that your function generates thumbnail and then tries to return the binary image within the html document. Html contains *links* to images, not the images themselves. So you need to do something like this: img src=create_thumbnail.php?filename=? echo $photo_img_name; ? Then you create_thumbnail.php can return the binary image: ? // be sure to validate the user supplied parameter! $photo_img_name = $_REQUEST['filename']; $percent = 0.5; list($width, $height) = getimagesize($photo_img_name); $newwidth = $width * $percent; $newheight = $height * $percent; $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefrompng($photo_img_name); imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // or whatever the correct mime/type is header(Content-type: image/png); echo imagepng($thumb); } I assumed there are no problems with the html part of things as the original image was being display perfectly. Guess thats where the difference between newbies and old hands is evident. I have added the suggested validation. Many thanks for all the help. regards Punit Neb -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php