php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #19817 ImageCreateFromGD2() doesnt recognize uncompressed .gd2 images
Submitted: 2002-10-08 11:15 UTC Modified: 2003-08-17 16:57 UTC
From: sprice at wisc dot edu Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4CVS-2002-10-08 OS: Darwin 6.1 (Mac 10.2.1)
Private report: No CVE-ID: None
 [2002-10-08 11:15 UTC] sprice at wisc dot edu
ImageCreateFromGD2() does not recognize a uncompressed gd2 
file. It seems to work just fine with compressed GD2 files, 
but I am having problems compressing a GD2 file of mine. 
(pngtogd2 gives a "Bus error" when I try to compress, not a 
PHP problem tho)

This script:
<?php
header( "Content-type: image/png" );
$medimg = $_SERVER['DOCUMENT_ROOT'] . "/riverdata/images/
world_map_med.gd2";

$medimg = ImageCreateFromGD2Part( $medimg, $x, $y, 800, 600 
);

$img = ImageCreateTrueColor( 800, 600 );
ImageCopy( $img, $medimg, 0, 0, 0, 0, 800, 600 );
ImageDestroy( $medimg );
ImagePNG( $img );
ImageDestroy( $img );
?>

Leaves this in the error log:
[Tue Oct  8 09:25:50 2002] [error] PHP Warning:  
imagecreatefromgd2part() [<a href='http://www.php.net/
function.imagecreatefromgd2part'>
function.imagecreatefromgd2part</a>]: '/Library/WebServer/
Documents/riverdata/images/world_map_med.gd2' is not a 
valid GD2 file in /Library/WebServer/Documents/riverdata/
scripts/test.php on line 3
[Tue Oct  8 09:25:50 2002] [error] PHP Warning:  
imagecopy(): supplied argument is not a valid Image 
resource in /Library/WebServer/Documents/riverdata/scripts/
test.php on line 4
[Tue Oct  8 09:25:50 2002] [error] PHP Warning:  
imagedestroy(): supplied argument is not a valid Image 
resource in /Library/WebServer/Documents/riverdata/scripts/
test.php on line 4

The error occours when I use this command to create the GD2 
file:
% /usr/local/bin/pngtogd2 world_map_med.png 
world_map_med.gd2 800 1

and doesn't when I use this:
% /usr/local/bin/pngtogd2 world_map_med.png 
world_map_med.gd2 800 2

Usage: pngtogd2 filename.png filename.gd2 cs fmt
    where cs is the chunk size
          fmt is 1 for raw, 2 for compressed

The files that I am using can be found here:
http://144.92.10.251/riverdata/images/

Keep in mind tho that I have no way of telling that a valid 
GD2 file is being created in the first place because I know 
of nothing else that uses (or creates) the GD2 file format 
other than the GD library itself.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-10 03:14 UTC] mfischer@php.net
Maybe Darwin/Mac related problem, works fine under Linux.
 [2002-10-10 08:22 UTC] sprice at wisc dot edu
Are you using the GD2 files at my site? I have reencoded them to work. Do you want me to make an example GD2 file that doesn't work?
 [2002-10-10 09:39 UTC] sprice at wisc dot edu
I have added an uncompressed version of the map at the 
site. It is called "uncompressed_med.gd2"

If you are interested in where I got these huge world 
images, I got them from a nasa site. You can download them 
if you would like :-)

To give credit where it is due:
http://visibleearth.nasa.gov/cgi-bin/viewrecord?11656
 [2002-10-10 10:08 UTC] sprice at wisc dot edu
I have added an uncompressed version of the map at the 
site. It is called "uncompressed_med.gd2"

If you are interested in where I got these huge world 
images, I got them from a nasa site. You can download them 
if you would like :-)

To give credit where it is due:
http://visibleearth.nasa.gov/cgi-bin/viewrecord?11656
 [2002-10-10 10:08 UTC] kalowsky@php.net
I'm going to say.. it's probably not an OSX/Darwin issue.  GD is GD, and it's been proven to be buggy in the past.  Although my hunting time is limited, I'll try to look at it later tonight.

Can you by any chance include a backtrace for this?
 [2002-10-10 10:21 UTC] sprice at wisc dot edu
Will a backtrace work? PHP isn't crashing, just giving an 
error.
 [2002-10-10 11:10 UTC] kalowsky@php.net
shhhh, don't prove  to me that I need more sleep than I'm getting ;)

okay nm that bt request... 
 [2002-10-11 06:15 UTC] mfischer@php.net
Did test http://144.92.10.251/riverdata/images/uncompressed_med.gd2 and got the following:

$ php 19817.php
Error from seek: 25

Warning: imagecreatefromgd2part() [http://www.php.net/function.imagecreatefromgd2part]: 'uncompressed_med.gd2' is not a valid GD2 file in /home/mfischer/src/php/bugs/gd/19817.php on line 7
/home/mfischer/src/php/bugs/gd/19817.php(7) : Warning - imagecreatefromgd2part() [http://www.php.net/function.imagecreatefromgd2part]: 'uncompressed_med.gd2' is not a valid GD2 file

Warning: imagecopy(): supplied argument is not a valid Image resource in /home/mfischer/src/php/bugs/gd/19817.php on line 10
/home/mfischer/src/php/bugs/gd/19817.php(10) : Warning - imagecopy(): supplied argument is not a valid Image resource

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/mfischer/src/php/bugs/gd/19817.php on line 11
/home/mfischer/src/php/bugs/gd/19817.php(11) : Warning - imagedestroy(): supplied argument is not a valid Image resource
PNG

IHDR vpkIDATx??1 ?????$ [binary scumm]


The interesting thing I think is "Error from seek: 25" which actually comes from the bundled libgd from libgd/gd_gd2.c from gdImageCreateFromGd2PartCtx, line 584:

          if (gdSeek (in, dpos) != 0)
        {
          printf ("Error from seek: %d\n", errno);
          goto fail2;
        };


Error code 25 means "Inappropriate ioctl for device", no idea why this happens though.

Maybe a problem related from mixing PHP Streams and native access to FILE fd's ?
 [2002-10-19 21:06 UTC] sprice at wisc dot edu
FYI: this bug still exists in the latest CVS snapshot.
 [2002-10-29 21:38 UTC] sprice at wisc dot edu
Problem still exists using latest CVS snap and GD 2.0.4. (I thought I would mention it 'cause I have seen lots of GD work being done in both.)
 [2002-10-29 21:40 UTC] rasmus@php.net
This is more of a feature request.  As far as I know nobody is working on it.  I certainly don't need this functionality.  Feel free to submit a patch.
 [2003-02-05 18:50 UTC] sprice at wisc dot edu
Nope, it still dosen't work with either compressed or uncompressed images. I am using GD 2.0.11 to produce the GD2 images. You guys should sync up with the current GD so I can try using it, instead.
 [2003-08-17 16:57 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC