| LAST | Alpha Channels | NEXT |
|
There are times when an all-or-nothing approach to transparency isn't sufficient, like when you need the background to show through part or all of your image. In the 70's at New York Tech Catmull & Smith invented an approach to this problem called an alpha channel. Basically, a fourth channel is added to the image containing the values for the transparency of each pixel. Typically, this channel is of the same bit-depth as the others, but GD's alpha channel only supports values from 0 to 127. Alpha Channels are only supported in true color images. |
| int imageColorAllocateAlpha ( resource image, int red, int green, int blue, int alpha ) Behaves identically to imageColorAllocatewith the addition of the transparency parameter alpha which may have a value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent. |
| The color information functions have also been extended to support alpha channels. |
| int imageColorClosestAlpha ( resource image, int red, int green, int blue, int alpha ) Returns the index of the color in the palette of the image which is "closest" to the specified RGB value and alpha level. int imageColorExactAlpha ( resource image, int red, int green, int blue, int alpha ) int imageColorResolveAlpha ( resource image, int red, int green, int blue, int alpha ) |
| There are two different ways GD draws within truecolor images. In blending mode, the alpha channel component of the color supplied to all drawing functions determines how much of the underlying color should be allowed to shine through. As a result, GD automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. |
| int imageAlphaBlending ( resource image, bool blendmode ) Sets the blending mode for an image, allowing for two different modes of drawing on truecolor images. If blendmode is TRUE, then blending mode is enabled, otherwise disabled. Notice that AlphaBlending is ON by default. So, only use this function if you don't want to use AlphaBlending. |
| While this function is useful for manipulating layers of images within GD, it is not supported within any of the output file formats except for true color (not indexed) PNGs, and you must specify you want the PNG saved in a manner that supports it (i.e. PNG-24 vs. the standard PNG-8). Note also that not all browsers support PNG-24. |
| int imageSaveAlpha ( resource image, bool saveflag ) Sets the flag to attempt to save full alpha channel information (as opposed to single-color transparency) when saving PNG images. You have to unset alpha blending (imageAlphaBlending($im,FALSE)), to use it. |
| LAST | Table of Contents | Function Index | NEXT |