php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34336 ext/gd: imagerotate destroys transparency information
Submitted: 2005-09-01 21:41 UTC Modified: 2005-09-08 23:55 UTC
From: techtonik@php.net Assigned: pajoye (profile)
Status: Not a bug Package: Feature/Change Request
PHP Version: 4CVS (2005-08-31) OS: *
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: techtonik@php.net
New email:
PHP Version: OS:

 

 [2005-09-01 21:41 UTC] techtonik@php.net
Description:
------------
Imagerotate doesn't preserve transparency information.
Next image was used in example below:
http://img24.imageshack.us/img24/228/spritepaw8alpha2os.png


Reproduce code:
---------------
<?php

$sprName = "sprite_paw8_alpha.png";
$spr = imagecreatefrompng($sprName); //create sprite object

//get sprite's transparent color
$sprTransparent = imagecolortransparent($spr);

//sprite rotation
$rotate = 15;
//rotate sprite, ?keeping transparent pixels
$spr = imagerotate($spr, $rotate, $sprTransparent); 

header("Content-type: image/gif");
imagegif($spr);
imagedestroy($spr);

?>

Expected result:
----------------
Rotated image with transparent background.

Actual result:
--------------
Rotated image with black background.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-02 10:10 UTC] pajoye@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


Try the newly added 4th argument:

imagerotate($rsr, $angle, $bg_color, $keeptransparency);

However, note that this is interpolated colors in the destination images (rotated), meaning that if the original image has some antialiased artifacts with the bgd color, you will notice them in the rotated image (in your case, a white border), not much can be done against that.

--Pierre


 [2005-09-03 00:06 UTC] techtonik@php.net
Well, it works for PHP5, but what to do with PHP4?

Why it is impossible to change the behavior to keep transparency by default?

Why change transparent to black while rotating in PHP4? 

It still seems like a bug to me.

Why this doesn't work either?

...
$sprTransparent = imagecolortransparent($spr);

//sprite rotation
$rotate = 15;
$spr = imagerotate($spr, $rotate, $sprTransparent); 
$sprTransparent = imagecolortransparent($spr, $sprTransparent);
...
 [2005-09-03 00:36 UTC] techtonik@php.net
JFY, a new fourth parameter "ignore_transparent" was already added to imagerotate in PHP 5.1 - see http://php.net/imagerotate
 [2005-09-03 12:10 UTC] pajoye@php.net
> JFY, a new fourth parameter "ignore_transparent" was
> already added to imagerotate in PHP 5.1 - see 

I added it in HEAD after 5.0.x was branched, but thx for the notice :)

> Why it is impossible to change the behavior to keep 
> transparency by default?

BC Break, and second as you see with your picture, it is not the best result you can have, people tend to mix transparec and transparent color. There is an interpolation, which range to use to ignore the bgd color or a transparent color? There is no easy way without making the function way too complex.


> Why change transparent to black while rotating in PHP4?

It's a new _feature_. We do not add new feature to PHP4 and/or PHP5.0

Status closed then

--Pierre
 [2005-09-03 14:17 UTC] techtonik@php.net
>> Why it is impossible to change the behavior to keep 
>> transparency by default?

> BC Break, and second as you see with your picture, it is
> not the best result you can have, people tend to mix
> transparec and transparent color. 

What do you mean by "transparec and transparent color"?

> There is an interpolation, which range to use to ignore 
> the bgd color or a transparent color? There is no easy 
> way without making the function way too complex.

But what if bgd color is transparent color? 

>> Why change transparent to black while rotating in PHP4?

> It's a new _feature_. We do not add new feature to PHP4
> and/or PHP5.0

I doubt that users can call changing transparent color to black while rotating. This doesn't seem like a feature to me, sorry.
 [2005-09-03 14:20 UTC] techtonik@php.net
I doubt that users can call this _feature_. Should I post another bug to be marked "won't fix" for future reference to users who will ask again and again?
 [2005-09-03 14:37 UTC] pajoye@php.net
It is fixed, and there is no need of duplicate bugs. End of this topic.
 [2005-09-08 23:55 UTC] pajoye@php.net
Stop filling this bug.

The Release managers of each previous PHP version and I decide that this patch will not be merged. The old versions will contain only critical fixes. If you do not understand that, please complain to /dev/null.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC