[PHP 4, PHP 5, PHP 7, PHP 8]
imagecolortransparent — Define a color as transparent
Description
imagecolortransparent[GdImage $image
,
?int $color
= null
]: int
Return Values
The identifier of the new [or current, if none is specified] transparent color is returned. If color
is null
, and the image has no transparent color, the returned identifier will be -1
.
Changelog
8.0.0 | image expects a GdImage instance now; previously, a resource was expected.
|
8.0.0 | color is now nullable.
|
Examples
Example #1 imagecolortransparent[] example
The above example will output something similar to:
Notes
Note:
Transparency is copied only with imagecopymerge[] and true color images, not with imagecopy[] or pallete images.
Note:
The transparent color is a property of the image, transparency is not a property of the color. Once you have set a color to be the transparent color, any regions of the image in that color that were drawn previously will be transparent.
markglibres at yahoo dot com ¶
13 years ago
I've made a very simple script that will retain transparency of images especially when resizing.
NOTE: Transparency is only supported on GIF and PNG files.
Parameters:
$new_image = image resource identifier such as returned by imagecreatetruecolor[]. must be passed by reference
$image_source = image resource identifier returned by imagecreatefromjpeg, imagecreatefromgif and imagecreatefrompng. must be passed by reference
Sample Usage: [resizing]
erik at vectorsector dot net ¶
15 years ago
This script creates transparency for a unspecific RBG color for an already created PNG image. It also includes script of overlay text that does not get ruined in the process.
Use $bg_color = imagecolorat[$im,1,1]; for instance, if you made the transparent color in photoshop by clearing out all the color leaving you with the checkered background showing you it's empty.
email at vladislav dot net ¶
11 years ago
Pay attention, that some GIF images may not include a transparent color. A good example of forced transparency in resized GIF image was given by markglibres at yahoo dot com 29-Mar-2009 02:48. But sometimes the transparent color in GIF images can be not set. The problem is, that the color you force to be transparent can be used in the original GIF as opaque and you will loose that color in resized image. The solution is not to use some default transparent color and to leave the resized image without transparent color [the same as original GIF]. I used [nearly] the following code to make resized GIF images trnsparent only when the transparency is needed: