PHP 8.3.4 Released!

Imagick::getImageAlphaChannel

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

Imagick::getImageAlphaChannel检查图像是否有 alpha 通道

说明

public Imagick::getImageAlphaChannel(): bool

返回图像是否有 alpha 通道。

参数

此函数没有参数。

返回值

如果图像具有 alpha 通道值,则返回 true,否则返回 false,即图像是 RGB 而不是 RGBACMYK 而不是 CMYKA

错误/异常

错误时抛出 ImagickException。

更新日志

版本 说明
imagick 3.6.0 现在返回 bool;之前返回 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