imagesavealpha

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

imagesavealphaWhether to retain full alpha channel information when saving images

Опис

imagesavealpha(GdImage $image, bool $enable): bool

imagesavealpha() sets the flag which determines whether to retain full alpha channel information (as opposed to single-color transparency) when saving images. This is only supported for image formats which support full alpha channel information, i.e. PNG, WebP and AVIF.

Зауваження: imagesavealpha() is only meaningful for PNG images, since the full alpha channel is always saved for WebP and AVIF. It is not recommended to rely on this behavior, as it may change in the future. Thus, imagesavealpha() should be called deliberately also for WebP and AVIF images.

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

Параметри

image

Об'єкт GdImage, що повертається однією з функцій створення зображення, такою як imagecreatetruecolor().

enable

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

Значення, що повертаються

Повертає true у разі успіху або false в разі помилки.

Журнал змін

Версія Опис
8.0.0 Тепер image має бути примірником GdImage. Раніше очікувався gd-resource.

Приклади

Приклад #1 Basic imagesavealpha() Usage

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

// Turn off alpha blending
imagealphablending($png, false);

// Do desired operations

// Set alpha flag
imagesavealpha($png, true);

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

imagepng($png);
?>

Прогляньте також