Efficiently blend multiple images into one image

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
Ferenc
Posts: 5
Joined: 2012-11-05T02:29:50-07:00
Authentication code: 67789

Efficiently blend multiple images into one image

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Efficiently blend multiple images into one image

Post by fmw42 »

Ferenc
Posts: 5
Joined: 2012-11-05T02:29:50-07:00
Authentication code: 67789

Re: Efficiently blend multiple images into one image

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Efficiently blend multiple images into one image

Post 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.
Ferenc
Posts: 5
Joined: 2012-11-05T02:29:50-07:00
Authentication code: 67789

Re: Efficiently blend multiple images into one image

Post 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!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Efficiently blend multiple images into one image

Post by fmw42 »

exec() is just a PHP call and has nothing to do with Imagick.
Post Reply