Hi,
I have been using the Image Magick for a short time now, mainly for resizing images on upload and watermarking, so my knowledge is very limited.
I am putting together a new site and I want a montage of pictures glued together and overlapped by X number of pixels, then the overlapping pictures faded into each other.
For example, I have 5 200px wide pictures on the server which I want to sit side by side, overlapping each other by 20 pixels. Then those 20 overlapping pixels are dissolved so that the pictures fade into each other (But Only the 20 Overlapping Pixels), creating a 920px wide image that can then be saved.
Is this possible with ImageMagick? I am using the command line ImageMagick 6.2.8 with PHP
Fade Two Pictures Together
Re: Fade Two Pictures Together
That's exactly what I was looking for, thanks very much.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fade Two Pictures Together
#make alpha channels with 10 pixel ramps on left, right and both sides
convert -size 128x10 gradient: -rotate 90 -size 118x128 xc:white +append tmp1.png
convert tmp1.png -flop tmp2.png
convert tmp1.png tmp2.png -compose multiply -composite tmp3.png
# add alpha channels to each image, left ramp on left image, right ramp on right image and both ramps on all middle images
convert zelda3.jpg tmp2.png -compose copy_opacity -composite tmpA.png
convert zelda3.jpg tmp3.png -compose copy_opacity -composite tmpB.png
convert zelda3.jpg tmp3.png -compose copy_opacity -composite tmpC.png
convert zelda3.jpg tmp3.png -compose copy_opacity -composite tmpD.png
convert zelda3.jpg tmp1.png -compose copy_opacity -composite tmpE.png
#montage the images side by side with -10 pixel offset to make 10 pixel overlap
montage tmpA.png tmpB.png tmpC.png tmpD.png tmpE.png \
-background white -geometry -10+0 -tile x1 zelda3_montage5.png
(unfortunately montage does not allow parenthesis processing with -compose so all the above cannot be combined into one long command line).
In fact, as montage supports -compose, if the IM folks upgrade montage to allow the new -compose blend option one might be able to do all the above simply with the following (although it would be a simple blend in the overlap and not a ramped blend):
convert zelda3.jpg zelda3.jpg zelda3.jpg zelda3.jpg zelda3.jpg \
-geometry -10+0 -tile x1 \
-compose blend -set option:compose:args 50 zelda3_montage5.png
but it does not work at this time.
by the way look at
http://www.imagemagick.org/Usage/montage/#overlap
convert -size 128x10 gradient: -rotate 90 -size 118x128 xc:white +append tmp1.png
convert tmp1.png -flop tmp2.png
convert tmp1.png tmp2.png -compose multiply -composite tmp3.png
# add alpha channels to each image, left ramp on left image, right ramp on right image and both ramps on all middle images
convert zelda3.jpg tmp2.png -compose copy_opacity -composite tmpA.png
convert zelda3.jpg tmp3.png -compose copy_opacity -composite tmpB.png
convert zelda3.jpg tmp3.png -compose copy_opacity -composite tmpC.png
convert zelda3.jpg tmp3.png -compose copy_opacity -composite tmpD.png
convert zelda3.jpg tmp1.png -compose copy_opacity -composite tmpE.png
#montage the images side by side with -10 pixel offset to make 10 pixel overlap
montage tmpA.png tmpB.png tmpC.png tmpD.png tmpE.png \
-background white -geometry -10+0 -tile x1 zelda3_montage5.png
(unfortunately montage does not allow parenthesis processing with -compose so all the above cannot be combined into one long command line).
In fact, as montage supports -compose, if the IM folks upgrade montage to allow the new -compose blend option one might be able to do all the above simply with the following (although it would be a simple blend in the overlap and not a ramped blend):
convert zelda3.jpg zelda3.jpg zelda3.jpg zelda3.jpg zelda3.jpg \
-geometry -10+0 -tile x1 \
-compose blend -set option:compose:args 50 zelda3_montage5.png
but it does not work at this time.
by the way look at
http://www.imagemagick.org/Usage/montage/#overlap
Last edited by fmw42 on 2009-08-07T11:40:44-07:00, edited 3 times in total.
Re: Fade Two Pictures Together
Done. The patch will be available by sometime tomorrow. Thanks.In fact, as montage supports -compose, if the IM folks upgrade montage to allow the new -compose blend option one might be able to do all the above simply with the following (although it would be a simple blend in the overlap and not a ramped blend):
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fade Two Pictures Together
magick wrote:Done. The patch will be available by sometime tomorrow. Thanks.In fact, as montage supports -compose, if the IM folks upgrade montage to allow the new -compose blend option one might be able to do all the above simply with the following (although it would be a simple blend in the overlap and not a ramped blend):
Great. But perhaps I spoke too soon as my proposed solution is not as complete as may be necessary. However perhaps Anthony will be able to see/comment whether the new -compose blur if also permitted in montage would allow the blend to be done in a ramped fashion over the overlap area rather than the simple blend equally over the whole overlap that using -compose blend would only provide.
It may be to do it right, one still has to use a ramped mask on each image?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Fade Two Pictures Together
WARNING: The user -compose setting is used by montage for the final composition of pre-preared image 'cells' onto the background. Please ensure it is reset back to 'over' before reaching the end of the command.fmw42 wrote:In fact, as montage supports -compose, if the IM folks upgrade montage to allow the new -compose blend option one might be able to do all the above simply with the following (although it would be a simple blend in the overlap and not a ramped blend):
see Montage Transparency and Background Handling
http://www.imagemagick.org/Usage/montage/#bg
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Fade Two Pictures Together
Actually I would not use -compose blend, and -compose blur does not seem to be what is wanted at all!
Normal compose over is all that is needed with the appropriate overlap, and transparency masking
of just one image. That is one image is masked the other remains fully opaque. This is what 'dissolve'
does but is a 'whole image' way.
If the edges of BOTH images are masked, using the same (but negated) mask, the you need to 'plus' the two images together so the transparency adds together and the image returned to full-transparency. This is what 'blend', image masking, and 3 image composite masking does. Blend however does this on a 'whole image' way.
Also using -- actually miss-using -- montage in this way is not what I would recommend.
The BEST way to do this would be to use something like the 'layered image' pipeline example...
The second example in...
http://www.imagemagick.org/Usage/layers/#example
This lets you mask and position the second and later images correctly, in a loop (any number of images), before feeding them to the layer 'merge' command via a pipeline. In many ways this is what 'montage' actually does internally!
In related things the current 'proposal' for 'layout' methods includes ideas to allow for spacing gaps in append like operations. Part of that is to correctly handle negative spacing or overlaped operations with correct 'edge' handling (that is spacing at edges does not go negative). This would be perfect for this type of thing, but as I said it is only a proposal waiting for some IM programmer to get 'to it'.
http://www.imagemagick.org/Usage/bugs/future/#layout
This proposal will let you implement montage like layouts (and more) from convert. Montage then could
end to to be simply a script to a convert command, with framing and layout processing on the end!
Normal compose over is all that is needed with the appropriate overlap, and transparency masking
of just one image. That is one image is masked the other remains fully opaque. This is what 'dissolve'
does but is a 'whole image' way.
If the edges of BOTH images are masked, using the same (but negated) mask, the you need to 'plus' the two images together so the transparency adds together and the image returned to full-transparency. This is what 'blend', image masking, and 3 image composite masking does. Blend however does this on a 'whole image' way.
Also using -- actually miss-using -- montage in this way is not what I would recommend.
The BEST way to do this would be to use something like the 'layered image' pipeline example...
The second example in...
http://www.imagemagick.org/Usage/layers/#example
This lets you mask and position the second and later images correctly, in a loop (any number of images), before feeding them to the layer 'merge' command via a pipeline. In many ways this is what 'montage' actually does internally!
In related things the current 'proposal' for 'layout' methods includes ideas to allow for spacing gaps in append like operations. Part of that is to correctly handle negative spacing or overlaped operations with correct 'edge' handling (that is spacing at edges does not go negative). This would be perfect for this type of thing, but as I said it is only a proposal waiting for some IM programmer to get 'to it'.
http://www.imagemagick.org/Usage/bugs/future/#layout
This proposal will let you implement montage like layouts (and more) from convert. Montage then could
end to to be simply a script to a convert command, with framing and layout processing on the end!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Fade Two Pictures Together
The problem here is that you want to ramp one image up while you ramp the other image down both in a linear fashion within the overlap. Your method, I do not believe, does that. Correct me if I am wrong.The BEST way to do this would be to use something like the 'layered image' pipeline example...
The second example in...
http://www.imagemagick.org/Usage/layers/#example
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Fade Two Pictures Together
Adding a transparency ramp to one image and 'over' laying it is EXACTLY the same as...adding the ramp to both images (a negated ramp that is) and blend or 'Plus' adding the images.
That is how the compose operators are designed and the difference between using 'over' vs 'plus' (or 'dissolve' vs 'blend' respectivally). I checked the math on this years ago the first time I when though the various composition methods, and re-check it again just to be sure.
This 'over' vs 'plus' handling difference is the key to understanding any form of region masking so as to ensure that you do not leave gaps, or semi-transparent pixels, or handling existing semi-transparent pixels in 'shaped images' correctly.
Remember 'over' only needs one image masked WHILE 'plus' needs both images masked with a negative mask of each other.
The only time you get different results is if BOTH images already contain an existing shape mask! In that case the 'plus' with 'dst-in' and 'dst-out' performed on each image (to multiply the alpha channels correctly), or a 3-image blend method works better.
For an example of DIY 3-image composition, using 'Dst-In', 'Dst-Out', and 'Plus' see
http://www.imagemagick.org/Usage/compose/#dstout
I also go though this in more detail in the bug report of 3 image alpha composition
http://www.imagemagick.org/Usage/bugs/c ... k/#correct
NOTE using Dst-In and Dst-out is the same as using CopyOpacity (negated on the other image), BUT only if both images did not already contain transparency. That is they were not a 'shaped' image. The Dst-In, Dst-Out is the more universal method of adding transparency to images.
That is how the compose operators are designed and the difference between using 'over' vs 'plus' (or 'dissolve' vs 'blend' respectivally). I checked the math on this years ago the first time I when though the various composition methods, and re-check it again just to be sure.
This 'over' vs 'plus' handling difference is the key to understanding any form of region masking so as to ensure that you do not leave gaps, or semi-transparent pixels, or handling existing semi-transparent pixels in 'shaped images' correctly.
Remember 'over' only needs one image masked WHILE 'plus' needs both images masked with a negative mask of each other.
The only time you get different results is if BOTH images already contain an existing shape mask! In that case the 'plus' with 'dst-in' and 'dst-out' performed on each image (to multiply the alpha channels correctly), or a 3-image blend method works better.
For an example of DIY 3-image composition, using 'Dst-In', 'Dst-Out', and 'Plus' see
http://www.imagemagick.org/Usage/compose/#dstout
I also go though this in more detail in the bug report of 3 image alpha composition
http://www.imagemagick.org/Usage/bugs/c ... k/#correct
NOTE using Dst-In and Dst-out is the same as using CopyOpacity (negated on the other image), BUT only if both images did not already contain transparency. That is they were not a 'shaped' image. The Dst-In, Dst-Out is the more universal method of adding transparency to images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/