版本更新后通过Imagick应用位移贴图 [英] Apply displacement map via Imagick after version update

查看:262
本文介绍了版本更新后通过Imagick应用位移贴图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了通过ImageMagick v6.7.9和PHP(Imagick扩展名v3.2.0)创建圆柱体"效果的代码,就像在上一个问题的可接受答案中所描述的:https://stackoverflow.com/a/54807019/1800172 灵感来自Fred的圆柱化脚本:

I had the code running to create a "cylinder" effect via ImageMagick v6.7.9 and PHP (Imagick extension v3.2.0), it's like described in the accepted answer of my previous question: https://stackoverflow.com/a/54807019/1800172 It's inspired by Fred's cylinderize script: http://www.fmwconcepts.com/imagemagick/cylinderize/

创建X/Y位移($a3/$a4)后,将其组合为:

After creating the X/Y-displacements ($a3/$a4) it's combined like this:

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

$displaceMask->setImageArtifact('compose:args', '1600x83.669513037752');
$image->compositeImage($displaceMask, Imagick::COMPOSITE_DISPLACE, 0, 0);
$image->trimImage(0);

现在我更新到ImageMagick v6.9.10和Imagick v3.4.3,不再产生相同的图像.我已经弄清楚了,我必须改变创建位移图的方式,以使其看起来与以前相同:

Now that I updated to ImageMagick v6.9.10 and Imagick v3.4.3 this does not produce the same image anymore. I already figured out that I had to change the way how to create the displacement map, to make it look the same as before:

// merge x-displacement and y-displacement into one displacement-map
$displaceMask = new Imagick();
$displaceMask->newImage($a3->getImageWidth(), $a3->getImageHeight(), new ImagickPixel('white'));
$displaceMask->setImageFormat('png');
$displaceMask->setImageColorspace(Imagick::COLORSPACE_RGB);

$displaceMask->compositeImage($a3, imagick::COMPOSITE_COPYRED, 0, 0);
$displaceMask->compositeImage($a4, imagick::COMPOSITE_COPYGREEN, 0, 0);
$displaceMask->compositeImage($a4, imagick::COMPOSITE_COPYBLUE, 0, 0);

但是,如果我现在将"composite"函数与"displace"运算符一起应用,则结果看起来与旧版本不一样:

But if I now apply the "composite" function with "displace" operator, the result looks not the same as with the old version:

$displaceMask->setImageArtifact('compose:args', '1600x83.669513037752');
$image->compositeImage($displaceMask, Imagick::COMPOSITE_DISPLACE, 0, 0);
$image->trimImage(0);

输入图像:

排量图:

预期的结果图像(如版本更新之前):

Expected resulting image (like before version update):

生成的图片(即版本更新后):

Resulting image (i.e. after version update):

我的猜测是,Imagick和/或ImageMagick实现或它的(默认)配置中发生了任何更改.谁能指出我的解决方案?

My guess is that anything changed in Imagick and/or ImageMagick implementation, or in it's (default) configuration. Anyone who can point me to the solution?

提前谢谢!

编辑:我更新了输入图像,而不是用作位移输入的图像.

Edit: I updated the input image, it was not the one that I use as the input of the displacement.

Edit2 :我尝试直接通过ImageMagick而不是使用Imagick来应用置换,并且它似乎可以正常工作(忽略了所生成的图像以某种方式被像素化的事实,因此它不能用作到目前为止的解决方法):

Edit2: I tried to apply the displacement via ImageMagick directly instead of using Imagick, and there it seems to work (ignoring the fact that the resulting image is somehow pixelated, so it's not usable as a workaround so far):

convert input.png ( a3.png a4.png a4.png -combine ) -channel rgba -alpha on -virtual-pixel transparent -background none -define compose:args=1600x83.669513037752 -compose displace -composite result.png

->可能是Imagick本身的问题/错误/更改吗?

--> Might be a problem/bug/change in Imagick itself?

推荐答案

我认为问题是ImageMagick和/或Imagick PHP扩展之间的更改.我在ImageMagick的变更日志中发现了此问题: https://github.com/ImageMagick/ImageMagick/问题/597 这里更进一步的是他们前一段时间所做的实际更改: https://github.com /ImageMagick/ImageMagick/commit/87be42439e1df8c51e7af5ea5d6591a8af499cf2

I think the problem was a change within ImageMagick and/or the Imagick PHP-extension between the versions that I used. I found this issue in the changelog of ImageMagick: https://github.com/ImageMagick/ImageMagick/issues/597 And one step further here is the actual change they did some time ago: https://github.com/ImageMagick/ImageMagick/commit/87be42439e1df8c51e7af5ea5d6591a8af499cf2

->要解决此问题,我不得不在composition参数上而不是在置换图上设置composition参数,而是在源图像上设置.然后,即使没有锯齿状的行,它也能再次正常工作(通过命令行尝试时也有锯齿状的行.)

--> to solve the issue, I had to set the compose arguments not on the displacement map, but instead on the source image. Then It was working fine again, even without the jagged lines (I had them as well when I tried it via the command line).

所以不是

$displaceMask->setImageArtifact('compose:args', '1600x83.669513037752');
$image->compositeImage($displaceMask, Imagick::COMPOSITE_DISPLACE, 0, 0);

我必须这样做:

$image->setImageArtifact('compose:args', '1600x83.669513037752');
$image->compositeImage($displaceMask, Imagick::COMPOSITE_DISPLACE, 0, 0);

这篇关于版本更新后通过Imagick应用位移贴图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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