Name | Description |
---|---|
imagecolorallocatealpha($i, $r, $g, $b, $a) |
Returns an identifier for the transparent (alpha) color of the specified image. The RGB values specify the color. The alpha value specifies the amount of transparency. This value can range from 0 to 127 with 127 being completely transparent. |
imagecolortransparent($i, $a) |
Sets the transparent color in the specified image. |
imagealphablending($i, $f) |
To turn alpha blending mode off, set the second parameter to FALSE. |
imagesavealpha($i, $f) |
To attempt to save full alpha channel information, set the second parameter to TRUE. For this to work, alpha blending mode must be turned off. |
// code that calculates the width and height for the new image // and sets the image type for the new image $new_image = imagecreatetruecolor($new_width, $new_height); // Set transparency according to image type if ($image_type == IMAGETYPE_GIF) { $alpha = imagecolorallocatealpha($new_image, 0, 0, 0, 127); imagecolortransparent($new_image, $alpha); } if ($image_type == IMAGETYPE_PNG || $image_type == IMAGETYPE_GIF) { imagealphablending($new_image, false); imagesavealpha($new_image, true); } // code that writes the new image to a file