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
Stacking images with transparency
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Stacking images with transparency
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
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Stacking images with transparency
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Stacking images with transparency
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!
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!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Stacking images with transparency
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
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