Imagemagick - move/offset images within a tiled montage?

时间:2019-01-18 18:42:32

标签: imagemagick imagemagick-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

2 个答案:

答案 0 :(得分:2)

在ImageMagick 6中,另一种方法是扩展透明背景,然后在扩展图像下半部分的中心合成蓝色图像。

convert -size 300x100 xc:red -background none -extent 300x200 -size 100x100 xc:blue -geometry +100+100 -composite result.png


enter image description here

答案 1 :(得分:2)

如评论中所建议:

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

enter image description here

或具有2个不同的偏移量:

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

不确定最终目标是什么,但是您也可以执行以下操作:

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

enter image description here

或者这个:

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

enter image description here