php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26144 ImageRotate() inverts/blacks the alpha channel
Submitted: 2003-11-05 17:52 UTC Modified: 2003-11-06 16:25 UTC
From: sprice at wisc dot edu Assigned:
Status: Not a bug Package: GD related
PHP Version: 4CVS-2003-11-06 OS: Mac 10.3
Private report: No CVE-ID: None
 [2003-11-05 17:52 UTC] sprice at wisc dot edu
Description:
------------
ImageRotate() is messing with my alpha channel. Examples 
to follow.

Reproduce code:
---------------
<?php
header( 'Content-type: image/png' );
$img = ImageCreate(100, 60);

$white = ImageColorResolve($img, 255, 255, 255);
$almost_clear = ImageColorResolveAlpha($img, 1, 1, 250, 63);

ImageFilledRectangle($img, 0, 0, 50, 30, $white);
ImageFilledRectangle($img, 10, 10, 100, 60, $almost_clear);

ImagePNG($img); // This works
//ImagePNG(ImageRotate($img, 90, $almost_clear)); // This is all black
?>

Expected result:
----------------
When you run this as is, you get a semitransparent blue 
rectangle.

Actual result:
--------------
If you replace the commented out ImagePNG() 
with the commented one, the alpha channel inverts 
itself. As you increase the transparency of 
$almost_clear, it becomes black (in contrast to the non-
ImageRotate() 
line).

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-05 19:46 UTC] sprice at wisc dot edu
Tried it with latest/greatest CVS (php4-STABLE
-200311060030) and it is still broken.
 [2003-11-05 21:39 UTC] sniper@php.net
And what might have been the configure line you used?
If you didn't use the bundled GD library, bogus this yourself..

 [2003-11-05 21:46 UTC] sprice at wisc dot edu
./configure --with-apxs --with-mysql --with-gd --with-
png-dir=/usr/local --with-zlib-dir=/usr --with-jpeg-
dir=/usr/local --disable-short-tags

(and phpinfo() says it is the bundled, 2.0.15 compat. 
version)

Is this not reproducible?
 [2003-11-06 13:31 UTC] sprice at wisc dot edu
After looking through the source code more, I think that 
this is caused (at least in part) by always converting 
the rotated image to a true color image, which always 
initially has the background color of black. This is 
also why the background color argument of the 
imageRotate() function seems to have no effect. This is 
shown in /ext/gd/libgd/gd.c on lines 2654, 2691, and 
2728 (among others).

I think a fix to this would be to make GD return a true 
color image only when the input is true color. Otherwise 
return an image with palette biased colors. This 
*should* keep the alpha channel a bit more intact than 
previously. Don't expect a patch from me any time soon 
though, because I have homework and classes now, and I 
only know enough C to be dangerous...
 [2003-11-06 16:25 UTC] iliaa@php.net
Change ImageCreate() to imagecreatetruecolor() and it'll work fine.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Aug 18 17:01:29 2024 UTC