|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-05-22 02:33 UTC] rryda at mgedata dot cz
Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: IDAT: CRC error in ..... The error appears only if PHP is run as CGI (php.exe). This functionality was used in 4.3.2RC3 successfully. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 08:00:01 2025 UTC |
More info: - PHP is run as CGI - using original windows binary pack - php_gd2.dll from original windows binary pack - web server: Apache 2.0.45 Imagecreatefrompng() is used in following code: //$image_file_url ... URL to the source 24-bit PNG file $image_base = ImageCreateTrueColor($map_width, $map_height); $white = ImageColorExact($image_base, 255, 255, 255); ImageFill($image_base, 0, 0, $white); // ........ $input = fopen($image_file_url, "rb"); $image_data = fread($input, 2000000); fclose($input); $image_file = tempnam("", "gd".rand(0, 10000)); $output = fopen($image_file, "w+b"); fwrite($output, $image_data); fclose($output); $image_tmp = ImageCreateFromPNG($image_file); // ERROR // ........Not really a bug; fread() will now (correctly!) return data in packet sized chunks when reading from network streams, as it did in PHP 4.2.x and earlier. Technically, your script is broken; you should either do this: <?php $data = ""; $fp = fopen("http://...."); do { $chunk = fread($fp, 8192); if (strlen($chunk) == 0) { break; } $data .= $chunk; } while (true); fclose($fp); ?> this: <?php $data = file_get_contents("http://..."); ?> or this: <?php copy("http://...", tempnam("", "gd")); ?> I'm making this a documentation problem, because the fread() manual page has never mentioned this fact, despite it being the behaviour since forever. One final note; the file_get_contents() and copy() functions were themselves suffering from a similar problem to that of your script; I've committed a fix to CVS, so you need to either use the fread() loop approach, or get the next stable snapshot (due in an hour or so).of course, the copy() version should look like this: <?php $local = tempnam("", "gd"); copy("http://", $local); ?> otherwise you don't know where you copied it to...