note 48900 added to function.imagecolortransparent
| From: | webmasteratwebnetwizarddotcodotuk at osu1 dot php dot net | Date: | Tue, 11 Jan 2005 14:09:57 +0000 |
| Subject: | note 48900 added to function.imagecolortransparent | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83080@lists.php.net to get a copy of this message | ||
After much devious mindbending, I have found a way to test any GIF for presence of background
transparency. This ability is essential for my application which uploads any of GIF, JPEG or PNG and
simultaneously creates a thumbnail of identical image type and identical filename (full size and
thumbnail versions being stored in different folders).
After uploading and moving the image in the usual way, a switch($image_type) statement ensures that
the optimum code is used to generate the thumbnail; regardless of image type.
The problem with the GIF type is that those with transparent backgrounds need to be treated
differently to those without. When I don't detect GIF transparency, I either end up with all
transparent GIF's having black backgrounds, or all GIF's get converted to transparent
background - even if they weren't transparent in the original.
But how to detect transparency in the original? It finally occurred to me that I could test for
transparency programmatically by overlaying a copy of the original image over an all-black image,
record the color value at particular pixel locations and then repeat the process by overlaying a
copy of the original image over an all-white image, recording the color values at identical pixel
locations and comparing these with the first set of values.
If the two sets of values correlate exactly, and if sensible sampling points are used, the image can
be treated as non-transparent. If the two sets of values show differences, the image should be
treated as having a transparent background.
----
Manual Page -- http://www.php.net/manual/en/function.imagecolortransparent.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48900
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48900&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48900&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48900&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48900&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48900&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48900&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48900&report=yes
Search -- http://master.php.net/manage/user-notes.php