Re: A black thumbnail.
| From: | Philip Hallstrom | Date: | Sat, 28 Jan 2006 00:49:38 +0000 |
| Subject: | Re: A black thumbnail. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229384@lists.php.net to get a copy of this message | ||
(skip down)
I'm trying to create a thumbnail from a jpeg stored in a long blob in mySQL. What's wrong here? I get an image that's the correct size, but it's black. Any ideas? <code> $dbQuery = "SELECT image_type, image, image_width, image_height "; $dbQuery .= "FROM pictures "; $dbQuery .= "WHERE image_Id = $pic_id"; $result = mysql_query($dbQuery) or die("Couldn't get file list"); if(mysql_num_rows($result) == 1) { $fileType = @mysql_result($result, 0, "image_type"); $fileContent = @mysql_result($result, 0, "image"); $width_orig = @mysql_result($result, 0, "image_width"); $height_orig = @mysql_result($result, 0, "image_height"); // Set a maximum height and width $width = 200; $height = 200; if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($fileContent);imagecreatefromjpeg takes a *filename* not the actual contents of the file itself. So $image is going to be invalid so your next command isn't going to do what you think which means you're going to get black as that's probably the first/default color of $image_p. -philip
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($image_p, null, 100); } </code> -- -------------------------------------------------------------------------------- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php