note 100200 modified in function.imagecolortransparent by danbrown
| From: | danbrown@php.net | Date: | Thu, 30 Sep 2010 16:16:07 +0000 |
| Subject: | note 100200 modified in function.imagecolortransparent by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172852@lists.php.net to get a copy of this message | ||
I would like to share with others how to make PNG image transparent. I have tried almost all
examples described on that page but none of them work for me. Finally I found the solution, but
there is a bit cheating :) but who cares if it works?
So when I tried to allocate white (as an example) color as a transparent, it worked randomly (lets
say 1 in 10 examples). That in turn pushed me to the idea that the problem is that white color is
already exist in color palette. So if I try to add another white color with DIFFERENT index as a
transparent, that will cause error.
So I found the solution, instead of adding new index, I searched for the white colorâs index in
the color palette and made it defined as transparent :) The best idea is to use not a white but left
bottom corner as transparent color (I guess that s standard for some other software languages).
<?php
$index = imagecolorexact($this->image, 255, 255, 255);
imagecolortransparent($this->image, $index);
?>
All you need is to add that two lines before outputting your result.
--was--
I would like to share with others how to make PNG image transparent. I have tried almost all
examples described on that page but none of them work for me. Finally I found the solution, but
there is a bit cheating :) but who cares if it works?
So when I tried to allocate white (as an example) color as a transparent, it worked randomly (lets
say 1 in 10 examples). That in turn pushed me to the idea that the problem is that white color is
already exist in color palette. So if I try to add another white color with DIFFERENT index as a
transparent, that will cause error.
So I found the solution, instead of adding new index, I searched for the white colorâs index in
the color palette and made it defined as transparent :) The best idea is to use not a white but left
bottom corner as transparent color (I guess that s standard for some other software languages).
<?php
$index = imagecolorexact($this->image, 255, 255, 255);
imagecolortransparent($this->image, $index);
?>
All you need is to add that two lines before outputting your result. You can see example of
transparent PNG at fastproxyservers.org. The transparent PNG image with graphic on top right corner
is generated with GD.
http://php.net/manual/en/function.imagecolortransparent.php