Edit report at http://bugs.php.net/bug.php?id=54482&edit=1
ID: 54482 User updated by: info822 at freshsoftware dot net Reported by: info822 at freshsoftware dot net Summary: imagecreatefromstring fails -Status: Feedback +Status: Open Type: Bug Package: GD related Operating System: Fedora 13 (Godard) Kernel Linux PHP Version: 5.3.6 Block user comment: N Private report: N New Comment: You couldnot reporduce the error because you apparently only looked at the live server. Please look at the DEV server. http://thewordsmith.dyndns.info/resize_event_pic.php?event_num=27&new_width=100&new_height=143 Previous Comments: ------------------------------------------------------------------------ [2011-04-07 21:59:38] paj...@php.net Cannot reproduce. Here is a simple script: <?php $file = 'https://secure20.nexcess.net/thewordsmith.info/images/event_images/2010-11- 20/The%20Lake%20Effect%20Festival/Lake%20Effect%20Hip%20Hop%20Flyer.jpg'; imagepng(imagecreatefromjpeg($file), 'a1.png'); imagepng(imagecreatefromstring(file_get_contents($file)), 'a2.png'); a1 and a2 are just fine. Please try this script as well. ------------------------------------------------------------------------ [2011-04-07 17:52:54] info822 at freshsoftware dot net A list off all the rpms installed on my system can be viewed at: http://thewordsmith.dyndns.info/rpms_installed.txt ------------------------------------------------------------------------ [2011-04-07 06:53:18] info822 at freshsoftware dot net Description: ------------ I am writing you because "imagecreatefromstring" is causing images to output black images. I have been using the same script on a live server running CentOS/PHP-5.1.6 and a development server running Fedora 9/PHP-5.2.3 for 1+ year with no problem. Recently I upgraded the dev server to Fedora 13/PHP-5.3.6 and now the same script has stopped displaying images. I have recompiled PHP, reinstalled http, httpd-devel, gd, gd-devel, libjpeg, libjpeg-devel, libpng, libpng-devel, and other related packages numerous times. But I can not figure out the problem. I would install PHP-5.2.3 on Fedora 13 but Openssl error out during the make process. ****************************************************************************** Here is some information about the liver server that does not have a problem. phpinfo: https://secure20.nexcess.net/thewordsmith.info/php/ Script View: https://secure20.nexcess.net/thewordsmith.info/resize_event_pic.php?event_num=27&new_width=100&new_height=143 Actual Image: https://secure20.nexcess.net/thewordsmith.info/images/event_images/2010-11-20/The%20Lake%20Effect%20Festival/Lake%20Effect%20Hip%20Hop%20Flyer.jpg Product script View: https://secure20.nexcess.net/thewordsmith.info/calendar.php ****************************************************************************** Here is info about the development server with the "imagecreatefromstring" problem: phpinfo: http://thewordsmith.dyndns.info/php/ Script View: http://thewordsmith.dyndns.info/resize_event_pic.php?event_num=27&new_width=100&new_height=143 Actual image: http://thewordsmith.dyndns.info/images/event_images/2010-11-20/The%20Lake%20Effect%20Festival/Lake%20Effect%20Hip%20Hop%20Flyer.jpg Production Script View: http://thewordsmith.dyndns.info/calendar.php ****************************************************************************** The logs are putting out "chunk" and "Corrupt JPEG data: 18580 extraneous bytes before marker 0xe2" errors. You can view all 3 error logs at: http://thewordsmith.dyndns.info/error_logs/ The development server is only on from 10am-6pm EST time. Email me when you are ready to look at this issue so I can be sure that the dev server is on. Test script: --------------- <? //ob_start(); //echo $HTTP_SERVER_VARS['HTTP_REFERER']; //DB connection. require "../db.php"; require "../globals.php" /* header ("Expires: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Cache-Control: no-cache, no-store, must-revalidate, private, max-age=0, proxy-revalidate, no-transform"); header ("Pragma: no-cache"); header("Vary: User-Agents"); */ //Now select the meber info. $get_calendar_info = mysql_query("SELECT * FROM `calandar` WHERE `event_num` = '$event_num' && `event_active` = 'yes'") or die(mysql_error(). ": " . __FILE__ . ": " . __LINE__); //or die(header("location: http://$none_secured_domain/error_page.php?profile_name_not_found")); $calendar_info = mysql_fetch_object($get_calendar_info); //Die to an errror if no such profile name exist. if(mysql_num_rows($get_calendar_info) <= 0){ mysql_close($mysql_connect); //die(header("location: http://$none_secured_domain/error_page.php?profile_name_not_found")); } if($calendar_info->event_img != ""){ $calendar_info->event_img = "$img_dir" . "/" . "$calendar_info->event_img"; } else{ //$calendar_info->event_img = "$img_dir" . "/" . "site/Calendar-Logo-256x256.png"; } $img_info = getimagesize("$calendar_info->event_img"); // get contents of a file into a string $img_data = file_get_contents("$calendar_info->event_img"); $thumb = imagecreatetruecolor($new_width, $new_height);// or die("Could create true color image. Error on file: " . __FILE__ . " Line: " . __LINE__); $source = imagecreatefromstring($img_data);// or die("Could create image from string. Error on file: " . __FILE__ . " Line: " . __LINE__); // Resize imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $img_info[0], $img_info[1]);// or die("Could not copy image Error on file: " . __FILE__ . " Line: " . __LINE__); // Output if($img_info[2] == 1){ header("Content-Length: " . filesize("$calendar_info->event_img")); header("Content-type: " . image_type_to_mime_type(IMAGETYPE_GIF)); imagegif($thumb); } elseif($img_info[2] == 2){ header("Content-Length: " . filesize("$calendar_info->event_img")); header("Content-type: " . image_type_to_mime_type(IMAGETYPE_JPEG)); imagejpeg($thumb); } elseif($img_info[2] == 3){ header("Content-Length: " . filesize("$calendar_info->event_img")); header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG)); imagepng($thumb); } imagedestroy($thumb); //ob_flush(); ?> Expected result: ---------------- Output of a thumbesize image which is reduced from a larger image. Actual result: -------------- A black images is out puted instead of a thumbebsize copy of a larger image. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54482&edit=1