Dutch PHP Conference 2025 - Call For Papers

Imagick::getImageAlphaChannel

(PECL imagick 2 >= 2.3.0, PECL imagick 3)

Imagick::getImageAlphaChannelVerifica se a imagem tem um canal alfa

Descrição

public Imagick::getImageAlphaChannel(): bool

Retorna se a imagem tem ou não um canal alfa.

Parâmetros

Esta função não possui parâmetros.

Valor Retornado

Retorna true se a imagem tiver um canal alfa e false se não tiver, ou seja, se a imagem for RGB ao invés de RGBA ou CMYK ao invés de CMYKA.

Erros/Exceções

Lança uma exceção ImagickException em caso de erro.

Registro de Alterações

Versão Descrição
imagick 3.6.0 Retorna agora um bool; anteriormente, retornava um int.
add a note

User Contributed Notes 1 note

up
1
phroggar
2 years ago
You want to check wether an image has an alpha channel? But you have no control which Imagick Version is used?

Background:

Method available since ImageMagick 6.4.0
Method returns boolean instead of int since 6.9.x

Example:

$image= new Imagick();
$image->readImage($source_file);

$imageHasAlphaChannel = (method_exists($image, 'getImageAlphaChannel') && ($document->getImageAlphaChannel() === \Imagick::ALPHACHANNEL_ACTIVATE || $document->getImageAlphaChannel() === true));
To Top