Imagick: compose with mask

纵饮孤独 提交于 2019-11-29 05:44:01

try using compositeImage method and Imagick::COMPOSITE_COPYOPACITY

Try this code:

// x-displacement
$a3->setImageArtifact('compose:args', "312x0");
$a1->compositeImage($a3, Imagick::COMPOSITE_DISPLACE, 0, 0);

// y-displacement
$a4->setImageArtifact('compose:args', "0x26.6776");
$a1->compositeImage($a4, Imagick::COMPOSITE_DISPLACE, 0, 0); 

After struggling with this I finally found a way how to do it properly with PHP-Imagick.

// merge x-displacement and y-displacement into one displacement-map
$displaceMask = new Imagick();
$displaceMask->addImage($a3);
$displaceMask->addImage($a4);
$displaceMask->addImage($a4);
$displaceMask->flattenImages();
$displaceMask = $displaceMask->combineImages(Imagick::CHANNEL_ALL);

$displaceMask->setImageArtifact('compose:args', '312x26.6776');
$a1->compositeImage($displaceMask, Imagick::COMPOSITE_DISPLACE, 0, 0);

Resources that I used:

I do not know if this will help, but I processed your images in ImageMagick 6.9.10.62 and 6.9.10.5 Q16 Mac OSX with the same result as shown below.

So if there is an issue, it is likely with Imagick.

What was your exact version of 6.9.10.x?

convert img.png \
\( dx.png dy.png dy.png -combine \) \
-define compose:args=312x26.6776 -compose displace -composite \
result.png


I notice that if the same image dx is combined for dy, then I get a result similar to your bad result. That might mean that either the addImage or the flattenImage or the combineImage is not working correctly in your new Imagick.

convert img.png \
\( dx.png dx.png dy.png -combine \) \
-define compose:args=312x26.6776 -compose displace -composite \
result2.png


Check your code to be sure you do not have a typo using $a3, $a3, and either $a3 or $a4 for your addImage.

For a test, try PHP

exec("convert img.png \( dx.png dy.png dy.png -combine \) -define compose:args=312x26.6776 -compose displace -composite result.png")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!