Please wait while we load your page...

Tools

PHP Manual [imagesavealpha]

Protect Your Website Today


PHP Manual || GD and Image Functions

(PHP 4 >= 4.3.2, PHP 5, PHP 7)

imagesavealphaWhether to retain full alpha channel information when saving PNG images

Description

imagesavealpha ( resource $image , bool $saveflag ) : bool

imagesavealpha() sets the flag which determines whether to retain full alpha channel information (as opposed to single-color transparency) when saving PNG images.

Alphablending has to be disabled (imagealphablending($im, false)) to retain the alpha-channel in the first place.

Parameters

image

An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().

saveflag

Whether to save the alpha channel or not. Defaults to FALSE.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

Example #1 Basic imagesavealpha() Usage

<?php
// Load a png image with alpha channel
$png imagecreatefrompng('./alphachannel_example.png');

// Turn off alpha blending
imagealphablending($pngfalse);

// Do desired operations

// Set alpha flag
imagesavealpha($pngtrue);

// Output image to browser
header('Content-Type: image/png');

imagepng($png);
imagedestroy($png);
?>

See Also



PHP Manual || GD and Image Functions