我想要设置一张图片的透明度,下面是当imagick的版本是6.8.9时不起作用。
<?php
// Open the original image
$image = new Imagick();
$image->readImage(3.jpg);
// Open the watermark
$watermark = new Imagick();
$watermark->readImage(2.png);
$watermark->setImageOpacity(0.4);
// Overlay the watermark on the original image
$image->compositeImage($watermark, imagick::COMPOSITE_OVER, 20, 20);
// send the result to the browser
header("Content-Type: image/" . $image->getImageFormat());
echo $image; 有没有其他方法来解决透明的问题?
发布于 2015-11-20 11:57:00
我已经找到了解决方案。
$watermark->setImageOpacity(0.4);
//It wouldn't work well because it would have a uniform effect On the picture.
$watermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, 0.4, Imagick::CHANNEL_ALPHA);
//It works well and have a satisfactory result.我用Go实现了这一点。下面的代码运行良好,运行成功。
mw = imagick.NewMagickWand()
mw.ReadImageBlob(src_image) // src_image is the source image
water_mw = imagick.NewMagickWand()
water_mw.ReadImageBlob(water_image) // water_image is the watermark image
// Set the transparent with 0.4
water_mw.EvaluateImageChannel(imagick.CHANNEL_ALPHA, imagick.EVAL_OP_MULTIPLY, 0.4)
//if water image has no alpha channel, replace with water_mw.EvaluateImage(imagick.EVAL_OP_MULTIPLY, 0.4)
// Composite the water image on source image, x, y are the coordinate u would composite
mw.CompositeImage(water_mw, imagick.COMPOSITE_OP_DISSOLVE, 20, 20)
dst_image = mw.GetImageBlob()https://stackoverflow.com/questions/33817792
复制相似问题