note 100200 added to function.imagecolortransparent

From: Date: Thu, 30 Sep 2010 16:00:29 +0000
Subject: note 100200 added to function.imagecolortransparent
Groups: php.notes 
Request: Send a blank email to php-notes+get-172851@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. You can see example of transparent PNG at fastproxyservers.org. The transparent PNG image with graphic on top right corner is generated with GD. ---- Server IP: 69.147.83.197 Probable Submitter: 92.243.21.120 ---- Manual Page -- http://www.php.net/manual/en/function.imagecolortransparent.php Edit -- https://master.php.net/note/edit/100200 Del: integrated -- https://master.php.net/note/delete/100200/integrated Del: useless -- https://master.php.net/note/delete/100200/useless Del: bad code -- https://master.php.net/note/delete/100200/bad+code Del: spam -- https://master.php.net/note/delete/100200/spam Del: non-english -- https://master.php.net/note/delete/100200/non-english Del: in docs -- https://master.php.net/note/delete/100200/in+docs Del: other reasons-- https://master.php.net/note/delete/100200 Reject -- https://master.php.net/note/reject/100200 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172851) next »