HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelDevelopmentTutorial Source codeReport an issue
Category
Example

Imagick::setImageAlphaChannel

← setCompressionQuality   setImageArtifact →
Activate or deactivate image alpha channel. The mode is one of the Imagick::ALPHACHANNEL_* constants. This method is available if Imagick has been compiled against ImageMagick version 6.3.8 or newer.

Theoretically, this table is meant to document what the different settings do exactly. But I am not entirely sure. PRs welcome!

Imagick::ALPHACHANNEL_ACTIVATE
Imagick::ALPHACHANNEL_DEACTIVATE
Imagick::ALPHACHANNEL_OPAQUE
Imagick::ALPHACHANNEL_SET

Example

function setImageAlphaChannel($alpha_type)
{
    $canvas = new Imagick();
    $canvas->newPseudoImage(640, 480, "pattern:checkerboard");
    $canvas->setImageFormat('png');

    $imagick = new \Imagick();
    $imagick->newPseudoImage(640, 480, "gradient:red-rgba(0, 0, 255, 0.1)");
    $imagick->setImageFormat('png');
    if ($alpha_type !== 0) {
        $imagick->setImageAlphaChannel($alpha_type);
    }

    $canvas->compositeImage($imagick, \Imagick::COMPOSITE_ATOP, 0, 0);

    header("Content-Type: image/png");
    echo $canvas->getImageBlob();
}