PHP imagick检测透明度 [英] PHP imagick detect transparency

查看:102
本文介绍了PHP imagick检测透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用Imagick PHP扩展来检测图像是否透明.

I want to be able to detect whether an image is transparent or not using the Imagick PHP extension.

到目前为止,我唯一碰到的是运行exec()/其他命令,并使用ImageMagick命令行工具来实现这一点.这就是我的意思:

So far, the only luck I've been having is to run the exec() / some other command, and use the ImageMagick command line tool to achieve this. Here's what I mean:

exec("identify -verbose example_transparent_image.png | grep \"Alpha\"", $output);
$is_transparent = !empty($output) ? true : false;

逻辑很简单.对相关图片进行详细检查:如果输出包含任何alpha信息,则表示它使用透明度.

The logic is simple. Do a verbose check on the image in question: if the output contains any alpha information, that means it uses transparency.

似乎PHP imagick扩展应该将此作为其命令之一,但是缺少文档却使我丧命.每次都要运行这种检查似乎很愚蠢.

It seems that the PHP imagick extension should have this as one of its commands, but the lack of documentation is killing me. It seems silly to have to run this kind of check each time.

推荐答案

啊,解决了(我认为). Imagick有一个getImageAlphaChannel()函数,如果它包含任何alpha信息,则返回true,否则包含false.

Ahhh, solved (I think). Imagick has a function getImageAlphaChannel() which returns true if it contains any alpha information and false if it doesn't.

确保您具有ImageMagick 6.4.0或更高版本.

Make sure you have ImageMagick 6.4.0 or newer.

http://www.php.net/manual/zh/function.imagick-getimagealphachannel.php

这篇关于PHP imagick检测透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆