Use of smush when combining images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
shveicar
Posts: 2
Joined: 2019-10-15T15:10:16-07:00
Authentication code: 1152

Use of smush when combining images

Post by shveicar »

Hello
I'm trying to figure out how to bring one of the layers to the foreground.
So it was be on top. When I use the command:

Code: Select all

convert granite: rose: -background none -gravity east +smush -10 test.png
I get a good result

Image

but when I change the command:

Code: Select all

convert rose: granite: -background none -gravity west +smush -10 test.png
to get the image on the left, one of the layers hides under the other

Image

How to make a layer with a rose on top?
Thanks
windows 10, ImageMagick 7.0.10.53
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Use of smush when combining images

Post by fmw42 »

smush will not overlap. It simply adds space or removes space.

You will need to do a -mosaic or -layers merge. See

https://imagemagick.org/Usage/layers/#mosaic
https://imagemagick.org/Usage/layers/#merge
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Use of smush when combining images

Post by snibgo »

Umm, smush can overlap.

As far as I know, smush always places the second on top of the first, and the third on top of that, and so on.

A couple of rotations will effectively reverse the order:

Code: Select all

convert granite: rose: -rotate 180 -background none -gravity west +smush -10 -rotate 180 rosegran.png
Image
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Use of smush when combining images

Post by fmw42 »

snibgo. Thanks I did not know that. I always thought it just added or deleted data as in the OP's original image. So I believe this does what you suggest:

Code: Select all

convert granite: rose: -reverse -background none -gravity east +smush -10 -flop granite_rose_smush.png
Image
User avatar
shveicar
Posts: 2
Joined: 2019-10-15T15:10:16-07:00
Authentication code: 1152

Re: Use of smush when combining images

Post by shveicar »

snibgo Many thanks for the tip, it is much more convenient than using other methods offered by fmw42

But there is such an interesting moment.
I have decomposed this animation into separate images (1-43.png) with using the utility FFmpeg

Image

After step by step combining each resulting image with a red-blue gradient (image2.png).
I used this command for vertical join with 10px indentation:

Code: Select all

convert image2.png 1.png -rotate 180 -background none -gravity South -smush 10 -rotate 180 +repage test.png
I noticed that in this case, the output images have slight differences in height. This is clearly seen when comparing the two images:

Image

I reassembled all the frames into an animation:

Image

If someone is interested the original images are here: https://www.sendspace.com/file/60dsez

But how can you replace, I got the shake effect of the pictures. I tried different ways to create animations, but the result was always the same.
I also tried putting a transparent background on the output images to bring them to the same size

Code: Select all

convert \( -size 111x156 xc:none \) test.png -gravity center -composite -compose Over +repage fin.png

But this did not lead to any distinctive changes.

How can I remove the jitter effect (the movement of the gradient up and down) when using the -smush method? to get something like this:

Image

This is the result I got when using this command:

Code: Select all

convert image2.png 1.png -background none +swap -append +repage test.png
but this method does not allow you to set the indentation between images and get the offset of layers as it does -smush

Thanks.
windows 10, ImageMagick 7.0.10.53
Post Reply