Imagemagick - move/offset images within a tiled montage? - imagemagick

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:
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):
... so to clarify - I'd like to know is its possible to move an image within a tile as obtained in montage tile 1x

As suggested in the comment:
convert -background none red.png \( -size 25x xc:none blue.png +append \) -append result.png
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
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
Or this:
convert -gravity center -background none red.png blue.png red.png blue.png -append result.png

In ImageMagick 6, another way is to extend the transparent background, then composite the blue image in the center of the bottom half of the extended image.
convert -size 300x100 xc:red -background none -extent 300x200 -size 100x100 xc:blue -geometry +100+100 -composite result.png

Related

Imagemagick Add Border to Inner Rectangle Only

I am trying to add a border to the 100x100 blue square only, without adding it to the 200x200 background red frame. How would I achieve this? I've experimented with many configurations including parentheses ().
exec("convert -size 200x200 xc:red -size 100x100 -draw rectangle -bordercolor yellow -border 2 xc:blue -geometry +5+5 -composite temp_bg.png ")
Try starting with the blue box, adding a border and then extending like this:
magick -size 100x100 xc:blue -bordercolor lime -border 10 -gravity northwest -background red -extent 400x400 -bordercolor yellow -border 10 result.png
Sorry, no time, gotta dash - add in a -page ... or -geometry ... before extent to set the position of the blue box.

How to draw a image on top of a shape

Simplified example:
I do create a cirlce like following:
magick convert -size 256x256 xc:none -fill #FFFFFF -draw "circle 128,128 256,128" +profile "icc" out.png
And I do convert a given image like following:
magick convert in.png -background none -gravity center -resize 181x181 +profile "icc" out.png
Question:
In my examples above I do have following "core" functions:
-size 256x256 xc:none -fill #FFFFFF -draw "circle 128,128 256,128" +profile "icc"
in.png -background none -gravity center -extent 181x181 +profile "icc"
How can I combine those images WITHOUT saving the first one to a temporary file? I want to create a 256x256 output image, draw the circle to this image and then draw the converted input image on top of the circle (centered).
My current solution
Create 2 different images and combine them like following:
magick convert -composite -gravity Center out1.png out2.png out.png
EDIT - FULL EXAMPLE
PS Script looks like following:
$in = ".\in.png"
$out1 = ".\tmp1.png"
$out2 = ".\tmp2.png"
$out = ".\out.png"
// 1) create circle image
magick convert -size 256x256 xc:none -fill #FFFFFF -draw "circle 128,128 256,128" +profile "icc" PNG32:$out1
// 2) convert input image
magick convert $in -background none -gravity center -resize 181x181 +profile "icc" -colorspace Gray -fill "#E91FCB" -colorize 50 PNG32:$out2
// 3) combine circle + converted image
magick convert -composite -gravity Center $out1 $out2 PNG32:$out
// 4) delete temp. images
Remove-Item $out1
Remove-Item $out2
Input Image:
Output Image (not visible, but it has the white circle as background + a transparent background otherwise):
You can use parenthesised processing like this:
magick -size 256x256 xc:none -fill white -draw "circle 128,128 256,128" \( in.png -background none -gravity center -resize 181x181 -colorspace Gray -fill "#E91FCB" -colorize 50 \) -composite result.png
On Windows, omit the \ before parentheses.

How to concatenate 3 images like a triangle using ImageMagick/GraphicsMagick

I have three images, a.jpg, b.jpg, c.jpg。
I want to concatenate them so they look like the follow:
I want to do this using one command. No tmp files generated.
How can I do this using IM/GM.
Another way in ImageMagick is to use smush rather then append. Smush allows offsets.
Create images:
convert -size 250x250 xc:green green.png
convert -size 250x250 xc:black black.png
convert -size 250x510 xc:red red.png
Now combine them:
convert -background white red.png \
\( green.png black.png -smush 10 \) \
+smush 10 \
result.png
Assuming the images are all the correct sizes, this is probably easiest:
convert -size 10x10 green.png xc:white black.png -append xc:white red.png -reverse +append result.png
That says... "make the size of the little spacers 10x10. Load the green image, then make a white spacer, then load the black image and append them together vertically. Make another white spacer. Load the red image. Reverse the columns of images so the most recently added red column is at the left instead of the right, append the images side-by-side."
I did it this way round (starting with the right side) because GraphicsMagick doesn't offer parentheses.
If the images are not already suitably sized, you would be looking at something more like this - still a single command:
convert -size 10x10 \
\( green.png -resize somehow \) \
xc:white \
\( black.png -resize somehow \) \
-append \
xc:white \
\( red.png -resize somehow \) \
-reverse +append result.png
One other way to do this in ImageMagick is just to composite the 3 images to the proper corners of a white background image.
Create images:
convert -size 250x250 xc:green green.png
convert -size 250x250 xc:black black.png
convert -size 250x510 xc:red red.png
Process:
convert -size 510x510 xc:white \
red.png -gravity northwest -composite \
green.png -gravity northeast -composite \
black.png -gravity southeast -composite \
result.png

Montage 3 images in a 2x2 grid, first in top center (like "triforce")?

Not sure how to put this question otherwise - but let's assume I have three square images. I'd like to arrange them in a sort of a square 2x2 grid, such that image 2 is bottom left, image 3 is bottom right - and image 1 is top center (so image 1 is not in the cells of the grid on top; neither left cell, nor right cell, but in center of the row delimited by them).
Closest I could get was with this test, done on Ubuntu 14.04, montage --version ImageMagick 6.7.7-10 2017-07-31 Q16:
montage \
<(convert -size 100x100 xc:green bmp:-) \
<(montage \
<(convert -size 100x100 xc:blue bmp:-) \
<(convert -size 100x100 xc:red bmp:-) \
-geometry +5+5 bmp:- \
) \
-geometry +5+5 -tile 1x2 bmp3:- | display
... or as one-liner:
montage <(convert -size 100x100 xc:green bmp:-) <(montage <(convert -size 100x100 xc:blue bmp:-) <(convert -size 100x100 xc:red bmp:-) -geometry +5+5 bmp:- ) -geometry +5+5 -tile 1x2 bmp3:- | display
The image produced is:
What I want instead is something like this (I edited this manually in an image editor):
... that is, somewhat like that old meme Triforce (Wikipedia)
How could I achieve that with ImageMagick's montage?
This might be a case where ImageMagick's "convert" command would serve you better than "montage". Here is an example that should get you pretty much the same result...
convert -size 100x100 xc:green xc:blue xc:red -bordercolor white -border 5 \
\( -clone 1,2 +append \) -delete 1,2 -gravity center -append -border 5 out.bmp
Using "convert" can give you more freedom to arrange the images using "+append" and "-append" to attach them, "-gravity" for alignment, and "-border" for spacing.

Imagemagick montage, different -extent values for 3 images

I have the following ImageMagick code that makes a poster out of 3 images, and it works well, however I would like to have a different -extent value for each of the 3 images. How would I do this? Any help would be much appreciated.
exec("montage -background black $img_1 $img_2 $img_3 -geometry 390x620+5+5 -gravity center -extent 396x626^ $img_out");
I still don't understand what you are trying to achieve, but I think the following might help you get where you are trying to go - hopefully!
I would tend to use convert rather than montage, so let's create three different size images, red, green and blue
convert -size 120x200 xc:red red.png
convert -size 200x300 xc:lime green.png
convert -size 80x120 xc:blue blue.png
they look like this
Now I try and make a poster, using a different shade of grey background for each "picture" and a different size and hope you can adapt that to your needs:
convert -gravity center \
\( -background gray70 red.png -extent 800x300 \) \
\( -background gray40 green.png -extent 300x300 \) \
\( -background gray10 blue.png -extent 100x300 \) \
+append result.png

Resources