Re: Trouble with thumbnail generation using GD
| From: | Justin Patrin | Date: | Wed, 21 Apr 2004 18:27:21 +0000 |
| Subject: | Re: Trouble with thumbnail generation using GD | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184154@lists.php.net to get a copy of this message | ||
Haddad Said wrote:
Hi, i was trying to create thumbnail using a tutorial on image galleries, I am having problems creating thumbnail images using GD. The thumbnail is created with the sizes prorerly, however the image is black. I have posted a temporary php file i created to investigate the problem below. I suspect the problem is with the imagecopyresampled function. I am using php version 4.3.4 with GD ver 2.0.x in windows XP for the test machine I appreciate any help Thanks PHP: <?php $submit = $_POST['submit']; if(isset($submit)) { $file = $_FILES['file']; $filename = "any.jpg"; move_uploaded_file($file['tmp_name'], $filename); $height = get_size($filename, "height"); $width = get_size($filename, "width"); $source_handle = ImageCreateFromJPEG($filename); $destination_handle = ImageCreateTrueColor($width, $height); ImageCopyResampled($destination_handle, $source_handle, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); ImageJPEG($source_handle, './tb_' . $filename); echo "Success!!"?><br><br><br><img src="./tb_any.jpg" /><? exit(); } function get_size($filename, $dimension) { global $images_dir; $size = GetImageSize($filename); // Wide Image if($size[0] > $size[1]) { $thumbnail_width = 100; $thumbnail_height = (int)(100 * $size[1] / $size[0]); } // Tall Image else { $thumbnail_width = (int)(100 * $size[0] / $size[1]); $thumbnail_height = 100; } if($dimension == "width") { return $thumbnail_width; } else { return $thumbnail_height; } } ?> <form action="<?=$PHP_SELF?>" name="frmAdd" method="post" enctype="multipart/form-data" > <p>Title:<br><input type="text" size="54" name="article_title" /></p> <p>Description:<br><textarea name="article_text" rows="10" cols="40"></textarea></p> <p>File:<br><input name="file" type="file" size="54" /></p> <p><input type="submit" name="submit" value="Submit" /></p></form>Check the color format of your image. If it's in CMYK (I think) then GD will choke on it. Make sure it's in RGB color mode. -- paperCrane <Justin Patrin>