Page 1 of 1

Stacking images with transparency

Posted: 2013-10-21T09:10:46-07:00
by lugiber
I have four images that i need to merge/stack to one image. But for the life of me i can't get image magick to do what i want.

Basically i want a background image with 100% opacity then i want to add another image on top of it with 70% opacity, then another image with 40% transparency and finally at the very top one with 10%. Thereby merging all four images to one.

I hope i have made myself clear. All the images have the same pixel dimensions.

Any imput would be very appreciated!

/Peter

Re: Stacking images with transparency

Posted: 2013-10-21T09:29:36-07:00
by fmw42
If the images already have the needed transparency, then

convert background image1 image2 image2 -background none -flatten result

If the images do not have transparency, then

convert background \
\( image1 -alpha set -channel a -evaluate set 70% +channel \) \
\( image2 -alpha set -channel a -evaluate set 40% +channel \) \
\( image3 -alpha set -channel a -evaluate set 10% +channel \) \
-background none -flatten result

Re: Stacking images with transparency

Posted: 2013-10-21T22:28:59-07:00
by anthony
Fred. didn't you arrange to add a 'weighted average' type operator. Hmmm.... -poly
That would be perfect for this. I'm surprised you didn't mention it.

Mind you your are overlaying (equivalent to -dissolve), rather than adding (equivalent to -blend, -average, and -poly) so I suppose your solution makes more sense.

Re: Stacking images with transparency

Posted: 2013-10-22T01:47:51-07:00
by lugiber
Thanks Fred!
That worked great!
If you don't mind i'd like to pick your brain one last time.

1.) Would it be possible to save the four images as a layered psd?
2.) Would it be possible to update the transparency of those layers with image magick after the file is saved?

It would be nice to have all the images as editable layers so that i can change the layer transparency after the files are merged without having to rewrite the entire file.
That would save some io on the harddrive.

Thanks!

Re: Stacking images with transparency

Posted: 2013-10-22T09:58:47-07:00
by fmw42
just try saving to PSD format without the -flatten. That should work but I have not tested.

convert background \
\( image1 -alpha set -channel a -evaluate set 70% +channel \) \
\( image2 -alpha set -channel a -evaluate set 40% +channel \) \
\( image3 -alpha set -channel a -evaluate set 10% +channel \) \
result.psd