php imagick,如何使一个区域透明 [英] php imagick, how to make an area transparent

查看:1133
本文介绍了php imagick,如何使一个区域透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在具有特定宽度,高度和顶部位置的Imagick对象中使区域透明。

I want to make an area transparent within an Imagick object with a specific width, height and a top position.

例如,我需要一个30px x的透明区域从第15个px到顶部30px,但我找不到办法。

For example I need a transparent area with 30px x 30px from the 15th px to the top but I can't find a way to do it.

$canvas1 = new Imagick();

$canvas1->newImage(30,60,'black','png');

请帮忙。

推荐答案

您可以按如下方式设置不透明度

You can set the opacity as follows

$image->setImageOpacity(0.0);

如果您将其设置为0.0,您所创建的图像将变为透明

If you set it to 0.0 the image what you have crated will become transparent

有关详细信息,请在Imagick中设置不透明度

如果你想要它用于特定区域部分那么你需要通过使用GD库函数来改变方法,做一些这样的事情

if you want it for a particular area part then you need to change the approach by using GD library functions by doing some what like this

 $img = imagecreatefrompng($imgPath); // load the image
 list($width,$height) = getimagesize($imgPath); // get its size
 $c = imagecolortransparent($img,imagecolorallocate($img,255,1,254)); // create      transparent color, (255,1,254) is a color that won't likely occur in your image
 $border = 10;
 imagefilledrectangle($img, $border, $border, $width-$border, $height-$border, $c); // draw transparent box
 imagepng($img,'after.png'); // save

我可以看到类似的要求发布在另一个论坛

I Could see a similar requirement which is posted in another forum here

这篇关于php imagick,如何使一个区域透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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