imagemagickimagemagick-montage

Imagemagick - move/offset images within a tiled montage?


Consider this example (Ubuntu 18.04, ImageMagick 6.9.7-4 Q16 x86_64 20170114):

convert -size 300x100 xc:red red.png
convert -size 100x100 xc:blue blue.png
montage red.png blue.png -frame 5 -geometry '+0+0' -tile 1x redblue.png

This gives the following image:

redblue.png

What I'd like to do, is move the blue square on arbitrary x position "within its tile"; say align left edge of blue square to where 25% of the red rectangle width would be, or at 50% - or even align right edge of blue square with right edge of red rectangle.

I have seen that -tile-offset exists (https://imagemagick.org/script/command-line-options.php#tile-offset), and I've tried it with this example, but it doesn't look like it does anything.

How can I move an image, part of a ImageMagick montage, within its tile?


EDIT: it looks like -tile-offset can only be specified for explicit tile images (not as in -tile 1x, but as in -tile red.png), and:

Tile smaller image over a background with offsets? - ImageMagick

-tile-offset must come before the tiling. It represents a single global offset, not the spacing for the tiling.

Here's an example:

convert -size 300x100 radial-gradient:\#400-\#FAA red.png
convert -size 500x500 xc: -tile-offset +100+40 +size -tile red.png  -border 5 -geometry +5+5  -draw "color 0,0 reset" out.png

then out.png is this (click for full image):

out.png

... so to clarify - I'd like to know is its possible to move an image within a tile as obtained in montage tile 1x


Solution

  • As suggested in the comment:

    convert -background none red.png \( -size 25x xc:none blue.png +append \) -append result.png
    

    enter image description here

    Or with 2 different offsets:

    convert -background none red.png            \
       \( -size 25x xc:none blue.png +append \) \
       \( -size 50x xc:none blue.png +append \) \
       -append result.png
    

    enter image description here

    Not sure what your end-goal is, but you can also do this:

    convert -gravity east -background none red.png blue.png red.png blue.png -append result.png
    

    enter image description here

    Or this:

    convert -gravity center -background none red.png blue.png red.png blue.png -append result.png
    

    enter image description here