php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19700 ImageCopy() fails with true color GD2 image
Submitted: 2002-10-01 20:12 UTC Modified: 2002-10-06 01:58 UTC
From: sprice at wisc dot edu Assigned:
Status: Closed Package: GD related
PHP Version: 4.2.3, 4.3.0-dev OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sprice at wisc dot edu
New email:
PHP Version: OS:

 

 [2002-10-01 20:12 UTC] sprice at wisc dot edu
When I am copying a true color image to a regular image using ImageCopy() PHP dies and nothing is returned.

ie:
(1 sec)
 1482 httpd       27.4%  0:10.96   1     8   164  3.77M- 13.1M+ 6.34M  38.2M+
(1 sec)
 1514 c++filt3     0.0%  0:00.01   1     9    14    48K   396K   268K  1.37M 
 1513 crashdump  102.5%  0:01.35   2    15   405  25.2M+ 21.1M+ 33.2M+ 59.7M+
 1482 httpd        0.0%  0:10.96   1     8   164  3.77M  13.1M+ 6.34M  38.2M 
(1 sec)
 1514 c++filt3     0.0%  0:00.01   1     9    14    48K   396K   268K  1.37M 
 1513 crashdump   99.8%  0:02.40   2    15   405  25.2M  21.1M  33.2M  59.7M 
 1512 top          4.7%  0:00.42   1    15    18   208K   376K   488K  13.8M 
 1482 httpd        0.0%  0:10.96   1     8   164  3.77M  13.1M  6.34M  38.2M 

Here are some example scripts. Notice that ImageCopyResized() works, but ImageCopy() doesn't in the last script.

This code works:
<?php
header( "Content-type: image/png" );

$medimg = $_SERVER['DOCUMENT_ROOT'] . "/riverdata/images/world_map_med.gd2";

//Work-around for another bug.
$x = (int) '1053';
$y = (int) '626';

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

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

$final_img = ImageCreate( 800, 600 );
imagecopyresized ( $final_img, $img, 0, 0, 0, 0, 800, 600, 800, 600);
ImageDestroy( $img );
$img = $final_img;

ImagePNG( $img );
ImageDestroy( $img );
?>

This code works:
<?php
header( "Content-type: image/png" );

$medimg = $_SERVER['DOCUMENT_ROOT'] . "/riverdata/images/world_map_med.gd2";

//Work-around for another bug.
$x = (int) '1053';
$y = (int) '626';

$img = ImageCreate( 800, 600 );

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

$final_img = ImageCreate( 800, 600 );
imagecopy ( $final_img, $img, 0, 0, 0, 0, 800, 600);
ImageDestroy( $img );
$img = $final_img;

ImagePNG( $img );
ImageDestroy( $img );
?>

This code works:
<?php
header( "Content-type: image/png" );

$medimg = $_SERVER['DOCUMENT_ROOT'] . "/riverdata/images/world_map_med.gd2";

//Work-around for another bug.
$x = (int) '1053';
$y = (int) '626';

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

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

ImagePNG( $img );
ImageDestroy( $img );
?>

This code works:
<?php
header( "Content-type: image/png" );

$medimg = $_SERVER['DOCUMENT_ROOT'] . "/riverdata/images/world_map_med.gd2";

//Work-around for another bug.
$x = (int) '1053';
$y = (int) '626';

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

$final_img = ImageCreate( 800, 600 );
imagecopy ( $final_img, $img, 0, 0, 0, 0, 800, 600);
ImageDestroy( $img );
$img = $final_img;

ImagePNG( $img );
ImageDestroy( $img );
?>

This code doesn't:
<?php
header( "Content-type: image/png" );

$medimg = $_SERVER['DOCUMENT_ROOT'] . "/riverdata/images/world_map_med.gd2";

//Work-around for another bug.
$x = (int) '1053';
$y = (int) '626';

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

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

$final_img = ImageCreate( 800, 600 );
imagecopy ( $final_img, $img, 0, 0, 0, 0, 800, 600);
ImageDestroy( $img );
$img = $final_img;

ImagePNG( $img );
ImageDestroy( $img );
?>

Sorry if this is a dupe. I some other bugs that may have something to do with this, but then again, maybe not. If you want a GD2 image for testing, you can use this one:
http://144.92.10.251/riverdata/images/world_map_med.gd2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-01 20:31 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip
 [2002-10-01 21:22 UTC] sprice at wisc dot edu
Nope, CVS snapshot doesn't work, same problem.

(It actually compiled on OS X without trouble. Weee!!)
 [2002-10-01 21:58 UTC] sprice at wisc dot edu
If it helps any, if you replace

$final_img = ImageCreate( 800, 600 );
imagecopyresized ( $final_img, $img, 0, 0, 0, 0, 800, 600, 800, 600);
ImageDestroy( $img );
$img = $final_img;

with

ImageTrueColorToPalette( $img, 'TRUE', 256 );

PHP still doesn't work and seems to have the same effect. This code has the same intention tho.
 [2002-10-01 22:16 UTC] sprice at wisc dot edu
Note:
this bug may be related to one that I just submitted here:
http://bugs.php.net/bug.php?id=19704
 [2002-10-02 06:12 UTC] sniper@php.net
Yes, part of the reason I wanted you to try 4.3.0-dev was to show that it compiles without trouble on macosx.. :)

Now, are you sure GD itself supports this what you try to do? As the GD extension in PHP is just a wrapper around the GD functions. You could also give a try for the bundled GD2 library we have now in 4.3.0-dev. Just configure with --with-gd=php to enable it. It has some fixes which are NOT in the 'official' gd distro.

 [2002-10-02 09:36 UTC] sprice at wisc dot edu
Welll... I did get compile warnings up the wazoo... but it worked, which is rather amazing.

I don't *know* if GD supports this, but it seems like a reasonable thing for it to do. It works in other functions. I need some way to convert a true color image to palette.

imagetruecolortopalette() doesn't work (see bug #19704)
imagecopy() doesn't work (this bug)
imagecopyresized() works (but is very slow, 3 secs on a fast server with plenty of ram)

I tried --with-gd=php and it seemed to run faster with imagecopyresized(), but still the same error with imagecopy().
 [2002-10-02 10:34 UTC] sniper@php.net
correct version numbers..

 [2002-10-02 11:02 UTC] sprice at wisc dot edu
I am getting lines in the apache error log file now (i wasn't in PHP v4.2.3)

It seems to be stuck in some sort of loop:
[Wed Oct  2 10:52:36 2002] [notice] child pid 24976 exit signal Segmentation fault (11)
[Wed Oct  2 10:52:38 2002] [notice] child pid 25017 exit signal Segmentation fault (11)
 [2002-10-02 16:31 UTC] sprice at wisc dot edu
I just noticed that if I downgrade libpng to v1.0.14 even ImageCopyResized() breaks in a similar fashion.
 [2002-10-05 01:48 UTC] iliaa@php.net
Can you try installing libpng v1.2.5 and then trying your code. There seems to be a good change that there is a bug in linpng that shows up on Mac OS systems. Maybe version 1.2.5 has this 'bug' fixed.
 [2002-10-05 10:02 UTC] sprice at wisc dot edu
Tried it, still doesn't work. I wish you guys would make the libpng version show up in phpinfo() so I could be sure I compiled everything right. If everything worked as advertised, I compiled libpng v1.2.5rc3. I configured with "--with-gd=/usr/local" and "--with-gd=php"
 [2002-10-05 15:39 UTC] kalowsky@php.net
Hrm you shouldn't be getting compiler warnings on OSX any worse than those that are normally found in PHP (unused variables, etc).  

Are you using an Apple provided libpng?

I have to admit I don't think we've done any real testing on GD yet, so you're sailing unknown waters.  
 [2002-10-05 16:49 UTC] sprice at wisc dot edu
If you want to see my PHP compile output I'll email it to you, but there are way too many warnings to cover in this thread. (I don't know what the normal number of PHP warnings is, I have only compiled it on Darwin.)

I didn't know that apple had a custom libpng. I have been using libpng that you can find on the png web site and compiling it myself with the tools provided by Apple.
http://www.libpng.org/pub/png/libpng.html
http://developer.apple.com/tools/projectbuilder/

heh.. ya, I noticed. The basic functions work well, but any strenuous use of GD is like walking on a minefield.

Thx for all of the help.
http://144.92.10.251/riverdata/map.html (work in progress)
This is what I am currently working on. Click on the map a few times to zoom in and see the stations. There are about 3,800 stations total. Each one measures the rate that water flows through the river that it is located on. It is a work in progress, so there is room for improvement on speed and file size. Eventually this map will be running on quite a verity of data in the department. Everything is rendered dynamically in PHP using a MySQL database. The labels are rendered realtime. They are partly transparent. They have drop shadows. They are clickable. The high-res source image is about 700-800 MBs total, using the GD2 image format (compressed). All of this is using work arounds for the batch of bugs that I have submitted. I am doing a nice test of GD for you guys :-)
 [2002-10-05 18:47 UTC] kalowsky@php.net
Hrm yeah it looks like there isn't an apple supplied libpng... for some reason I thought there was.

Okay it'll take me a little while to get that installed and moving.  In the meantime, what can YOU do to help us? <g>

Try compiling your PHP with debug options on and see if you're getting any warnings or notices in the error logs.  Feel free to forward me a copy of your buildlog, as I'd like to remove as many build warnings before 4.3 goes out the door.  


 [2002-10-05 20:15 UTC] sprice at wisc dot edu
I recompiled PHP with libpng v1.0.15 and v1.2.5. I used "--with-gd=/usr/local" and "--with-gd=php" (so I compiled 4 times total). Same problem every time.

While I was at it I compiled a debug build of PHP (libpng v1.2.5 and "--with-gd=php") and I got y'all a backtrace (if it helps much). There were no extra errors in Apache's error_log.

Here ya go:
Program received signal EXC_BAD_ACCESS, Could not access memory.
0x007c5060 in gdImageCopy (dst=0x19e250, src=0x272a90, dstX=0, dstY=0, srcX=0, srcY=0, w=800, h=600) at /usr/local/php-cvs/php4-200210050600/ext/gd/libgd/gd.c:1757
1757              if (colorMap[c] == (-1))
(gdb) bt
#0  0x007c5060 in gdImageCopy (dst=0x19e250, src=0x272a90, dstX=0, dstY=0, srcX=0, srcY=0, w=800, h=600) at /usr/local/php-cvs/php4-200210050600/ext/gd/libgd/gd.c:1757
#1  0x007bd7cc in zif_imagecopy (ht=8, return_value=0x1b2dd8, this_ptr=0x0, return_value_used=0) at /usr/local/php-cvs/php4-200210050600/ext/gd/gd.c:2489
#2  0x00983f28 in execute (op_array=0x19b3d8) at /usr/local/php-cvs/php4-200210050600/Zend/zend_execute.c:1597
#3  0x0096b8dc in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/local/php-cvs/php4-200210050600/Zend/zend.c:834
#4  0x009218ec in php_execute_script (primary_file=0xbfffec60) at /usr/local/php-cvs/php4-200210050600/main/main.c:1542
#5  0x00989cd0 in apache_php_module_main (r=0x193238, display_source_mode=0) at /usr/local/php-cvs/php4-200210050600/sapi/apache/sapi_apache.c:55
#6  0x0098aefc in send_php (r=0x193238, display_source_mode=0, filename=0x194db8 "/Library/WebServer/Documents/riverdata/scripts/test.php") at /usr/local/php-cvs/php4-200210050600/sapi/apache/mod_php4.c:564
#7  0x0098af7c in send_parsed_php (r=0x193238) at /usr/local/php-cvs/php4-200210050600/sapi/apache/mod_php4.c:579
#8  0x0000c4b4 in ap_invoke_handler ()
#9  0x000160b4 in process_request_internal ()
#10 0x00016144 in ap_process_request ()
#11 0x00005b48 in child_main ()
#12 0x00005d08 in make_child ()
#13 0x00005e74 in startup_children ()
#14 0x00006470 in standalone_main ()
#15 0x00006ce8 in main ()
#16 0x00001bb0 in _start ()
#17 0x00001a30 in start ()
(gdb)
 [2002-10-05 20:22 UTC] rasmus@php.net
In your backtrace there, just after you type, "bt", type:
"p c" and then "p i".  As far as I can tell, PHP is not calling this function incorrectly.  There must be some odd Mac-specific problem here.

 [2002-10-05 20:29 UTC] sprice at wisc dot edu
Silly Apple...

(gdb) p c
$1 = 1648905
(gdb) p i
$2 = 256
(gdb)
 [2002-10-05 20:39 UTC] wez@php.net
The problem is that the gd library assumes that the src
image is palette based if the destination is palette based.
That causes c to be set to the ARGB value instead of the palette index into the color map array, and hence the segfault.

 [2002-10-05 20:48 UTC] sprice at wisc dot edu
My girlfriend says that she will give everyone a hug if you fix this bug and #19704. :-)
 [2002-10-05 20:57 UTC] kalowsky@php.net
Good thing Wez knows the answer as I have been unable to get libpng 1.2.5 to compile on Jaguar.  They have some funky Makefile magic going on, and I don't have the patience right now to figure out their code.
 [2002-10-05 20:59 UTC] rasmus@php.net
Yeah, once we got the backtrace info, this one was easy.  I'll fix it in a bit unless Wez is doing it now.
 [2002-10-05 21:08 UTC] sprice at wisc dot edu
For compiling libpng in Jaguar I use:
% cp scripts/makefile.macosx ./Makefile
% make ZLIBINC="/usr/lib" ZLIBLIB="/usr/lib"
% sudo make install
% sudo ranlib /usr/local/lib/libpng.a

I get one error, but as far as I can tell it compiles the libpng.a just fine.

Error is:
cc -o pngtest -fno-common -I/usr/lib -O  pngtest.o -L. -L/usr/lib -lpng -lz -current_version 0.1.2.5
cc: -current_version only allowed with -dynamiclib
make: *** [pngtest] Error 1
 [2002-10-06 01:58 UTC] rasmus@php.net
Fixed in CVS - fix merged to 4.3 release branch

Note that copying a truecolor image to a palette-based image is going to be rather slow as each pixel's color is going to need to be interpolated.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 14:01:30 2024 UTC