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

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.

Related

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:
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

Convert multiple Imagemagick commands into 1 command (trim, resize, square)

Currently, I am using multiple imagemagick commands to trim, resize (if width or height > 5000) and square. Is it possible to combine into 1 single command?
step 1: convert input_file.tif -fuzz 1% -trim output_file_trim.tif
step 2: get new image width and height using identify command from output_file_trim.tif
step 3: get max dimension from image width and height
step 4: if max dimension > 5000 then
convert output_file_trim.tif -resize 5000x5000 output_file_trim.tif
Step 5: Finally, finish the image conversion
convert output_file_trim.tif -flatten -gravity center -background white -extent "$max_dimension"x"$max_dimension" -format jpg output_file_final.jpg
#fmw42. Is the following single command correct to achieve this requirement:
convert `input_file.tif` -fuzz 1% -trim +repage \( +clone -rotate 90 +clone -mosaic +level-colors white \) +swap -flatten -gravity center -extent 105x105% -composite -format jpg `output_file_final.jpg`
This command will read the input image and trim it. Then it resizes it to fit in a 5000x5000 box if it's larger than 5000x5000. Then it re-dimensions the canvas to a square with both dimensions being the larger of the width or height. It finishes by placing the image in the center of that square canvas with a white background.
convert input_file.tif -fuzz 1% -trim +repage -resize "5000x5000>" \
-set option:distort:viewport "%[fx:max(w,h)]x%[fx:max(w,h)]" -virtual-pixel white \
-distort affine "0,0 %[fx:h>w?(h-w)/2:0],%[fx:w>h?(w-h)/2:0]" \
output_file_final.jpg
Putting your 5 steps into one command can only be done in IM 7 as follows (unix syntax):
magick -quiet input_file.tif -fuzz 1% -trim +repage \
-resize "5000>" \
-flatten -gravity center -background white \
-extent "%[fx:max(w,h)>5000?5000:max(w,h)]x%[fx:max(w,h)>5000?5000:max(w,h)]" \
output_file_final.jpg
In IM 6, you need to do it in two command. First find the larger of the max(w,h) and 500 as dim and save a temp image from your step one. Then do another command to finish it using that dim
dim=$(convert -quiet input_file.tif -fuzz 1% -trim +repage \
+write output_file_final.jpg -format "%[fx:max(w,h)>5000?5000:max(w,h)]" info:)
convert output_file_final.jpg -resize "5000>" \
-flatten -gravity center -background white \
-extent ${dim}x${dim} output_file_final.jpg
I do not understand your last command. It does not relate to the steps you outlined.

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

How do I make the images equidistant using imagemagick/montage?

Currently I'm using this command:
montage IMG*.JPG -tile 3x1 -geometry 150x100+40+40 -background '#000000' triptych.jpg
And it produces an output like this (red lines added):
The problem (as indicated) is that my images have too much space between them, and that makes me sad.
I'm looking to create something that looks more like this, with the border equal all the way around:
I checked the manpage and several online guides, but none of the options that I tried (-mode concatenate, changing the geometry to +40+20) did what I wanted.
How do I get the output that I want using imagemagick?
If you are just making a triptych, you may get on better with convert +append to lay out images in a row with spacers. So, if your images are 1.png, 2.png and 3.png:
convert -background black \
1.png xc:black[10x] 2.png xc:black[10x] 3.png +append \
-bordercolor black -border 10 result.png
The xc:black[10] are just the two spacers that you can set the width of explicitly. Then the three images with spacers are set in a horizontal row, using +append. Finally, at the end, I put a border around the whole lot with -border.
Or, showing how you have full control over all aspects:
convert -background black \
1.png xc:black[15x] 2.png xc:black[5x] 3.png +append \
-bordercolor black -border 40 result.png
As Wayne says in the comments, you can resize all the images to a uniform size too, while they are still separate before the -append, so you can do this to make sure no image is wider than 400 pixels.
convert -background black \
1.png xc:black[10x] 2.png xc:black[10x] 3.png -resize 400x\> +append \
-bordercolor black -border 10 result.png
If you want even more control, you can individually resize the images like this:
convert -background black \
\( 1.png -resize WxH \) xc:black[10x] \
\( 2.png -resize AxB \) xc:black[10x] \
\( 3.png -resize MxN \) +append \
-bordercolor black -border 10 result.png
If you want a vertical triptych, use -append in place of +append and set the spacer height with xc:black[x10] rather than xc:black[10x].
convert -background black \
1.png xc:black[x10] 2.png xc:black[x10] 3.png -append \
-bordercolor black -border 10 result.png
Keywords: triptych, diptych, montage, photographer, photography, photo, spacing, spacer, padding
Another method is doing it in two steps.
montage img-*.png -background '#000' -geometry +20+20 step-1.png # step 1
convert step-1.png -bordercolor '#000' -border 20 step-2.png # step 2
With step 1, you got the green spacing. And with step 2, you got the red spacing

Combine and resize multiple images in a square using ImageMagick

So I want to create one large image of size 3600x2280 composed of three smaller images. The first should be resized to 1680x1050 and placed in the top left corner. The 2nd needs to be reiszed to 1920x1200 and placed immediately to the right of it (+1680 over). The 3rd image should be resized to 1920x1080 and placed on the bottom right (+1680+1200). The bottom left will just be blank/transparent.
I've tried various commands I've searched for online and think I'm getting somewhat close with something like the following for just two of the three images:
convert -define png:size=3600x2280 \( Photos/DSC05525-original.jpg -resize 1680x1050 \) -geometry +0+0 -composite \( Photos/Sydney-Loftus-Train-Station-original.jpg -resize 1920x1200 \) -geometry +1680+0 -extent 3600x2280 test.png
...but that places the 2nd image over the first (I think because it doesn't know to extend until the very end?). I've tried various combinations of -composite, -gravity and +repage, but can't seem to find a solution.
There are lots of ways of doing this. Choose the one that corresponds best to the way your mind works! I used test images like this:
1.jpg => red
2.jpg => green (lime actually)
3.jpg => blue
Method 1
convert -background none \
1.jpg -resize 1680x1050! \
\( 2.jpg -resize 1920x1200! \) +append \
\( 3.jpg -resize 1920x1080! -gravity east \) -append \
result.png
That says... "Leave all unpainted areas transparent. Resize image 1. Resize image 2 and place it to the right of image 1 (+append). Resize image 3 and align it East. Append that underneath images 1 and 2 (-append)."
Method 2
convert -background none \
\( 2.jpg -resize 1920x1200! \) \
\( 3.jpg -resize 1920x1080! \) -append \
\( 1.jpg -resize 1680x1050! \) +swap +append result.png
That says... "Load and resize image 2. Load and resize image 3. Place image 3 underneath image 2 (-append). Load and resize image 1. Place image 1 before (+swap) image 2 in the image list. Now append the second image in the list to the right of the first (+append)."
Method 3
convert -background none \
1.jpg -resize 1680x1050! -extent 3600x2280 \
\( 2.jpg -resize 1920x1200! -geometry +1680 \) -composite \
\( 3.jpg -resize 1920x1080! -geometry +1680+1200 \) -composite result.png
That says... "Leave any unpainted areas transparent. Load image 1 resize it then extend the canvas to the full output size to accommodate subsequent images. Load image 2, resize, position and splat onto canvas. Load image 3, resize and splat onto canvas."
Method 4
Just for fun, here's a totally different way of thinking about it:
{ convert 1.jpg -resize 1680x1050! miff:- ; \
convert 2.jpg -resize 1920x1200! miff:- ; \
convert -size 1680x1 xc:none miff:- ; \
convert 3.jpg -resize 1920x1080! miff:- ; } |
montage -background none -geometry +0+0 -tile 2x2 miff:- result.png
That says... "Start a compound statement that will load and resize 4 images and send each of them as a MIFF (Magick Image File Format) to a montage command that will put them all together in 2x2 grid (-tile 2x2) with no spaces between them (-geometry +0+0)."

Resources