Page 1 of 1

Efficiently blend multiple images into one image

Posted: 2012-11-13T06:10:17-07:00
by Ferenc
Dear reader,

I would like to compose multiple PNG images (with transparency) on a background image with the blending mode set to Overlay. What is the most efficient way to do this? Is this possible with Imagick, or do I have to execute ImageMagick in a shell via exec()? I'd rather use Imagick because I've read it wins on performance over a shell execution.

I have used the compositeImage() command so far, which works fine but when you have 12 images to blend, you have to execute this command 12 times. I've read some documentation about this issue at http://imagemagick.org/Usage/layers/#compose but I can't seem to translate this shell code to Imagick.

Thanks in advance,
Ferenc

Re: Efficiently blend multiple images into one image

Posted: 2012-11-13T10:43:01-07:00
by fmw42

Re: Efficiently blend multiple images into one image

Posted: 2012-11-14T06:57:38-07:00
by Ferenc
Thanks for the quick reply and the references. I thought flattenImages did not support blending modes. I will look in to it. Thanks!

Re: Efficiently blend multiple images into one image

Posted: 2012-11-14T11:03:23-07:00
by fmw42
I believe on common blend mode, but am not sure. In command line I think you can do that, but again not totally sure.

Re: Efficiently blend multiple images into one image

Posted: 2012-11-15T03:18:51-07:00
by Ferenc
I have to deliver this site within a few weeks, so I'll stick to my current solution for now. I blend all images one by one like this:

Code: Select all

$imTopLeather		= 	new Imagick($top_leather_url);
$imTopColor		= 	new Imagick();
$imTopColor		->	newImage(1000,450, $topColor);
$imTopColor		->	compositeImage($imTopLeather, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$imTopLeather		->	compositeImage($imTopColor, Imagick::COMPOSITE_OVERLAY, 0, 0);
I think using the convert method within a shell could be faster because you can run one command for multiple images. I've tried to achieve this by running ImageMagick with exec(), but I couldn't get it working. If there is an Imagick php command for this it would be awesome. First I'll stick to this method. Not the fastest, but it works!

Re: Efficiently blend multiple images into one image

Posted: 2012-11-15T10:43:04-07:00
by fmw42
exec() is just a PHP call and has nothing to do with Imagick.