3

I'm trying to recreate a script that uses the ImageMagick command "convert" to compose an image. But I want to do the same in PHP using Imagick:

convert ./a.png ./b.png ./c.png  -virtual-pixel transparent -channel rgba -alpha on -background transparent -define compose:args=300x53.033 -compose displace -composite ./final.png

a.png

Original

b.png

Overlay

c.png

Mask

Result:

Result obtained though command line

Where a.png is a base image, b.png is the overlay and c.png is the gray-scale 'mask'. For achieving this result, I've to execute all manipulations which are supported by the extension, write the image in disk and then execute this command through the exec function, which is a terrible workaround.

The following snippet does not work:

$a = new Imagick('../a.png');
$b = new Imagick('../b.png');
$c = new Imagick('../c.png');

$a->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$a->setImageBackgroundColor(new ImagickPixel('none'));
$a->setOption('compose:args', '300x53.033');
$a->compositeImage($c, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);
$a->compositeImage($b, Imagick::COMPOSITE_DISPLACE, 0, 0);

Result:

Result obtained though PHP

Expected:

Result obtained though command line

I would like to achieve this same result using only Imagick PHP.

Marcos Passos
  • 400
  • 1
  • 3
  • 15
  • I'm not familiar with the displace map feature, so I don't have an answer for how to make PHP give you the desired output, but I can tell you that this line is effectively a no-op in this case: `$a->compositeImage($c, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);` - I don't know if that helps at all. – TML Sep 25 '14 at 02:09
  • I thik this is a duplicate of https://stackoverflow.com/questions/13232551/imagick-compose-with-mask -- I added the solution there as well (I guess you did it the same way, according to https://github.com/mkoppanen/imagick/issues/49) – Michael Feb 21 '19 at 12:26
  • Possible duplicate of [Imagick: compose with mask](https://stackoverflow.com/questions/13232551/imagick-compose-with-mask) – Michael Feb 22 '19 at 07:52

0 Answers0