How to insert one row spacing between tiles in a tiled image using Imagemagick? - imagemagick

I have a bunch of images that I want to tile together in one row. This can be done using Imagemagick montage like this
montage `ls tile*.png` -tile x1 -gravity west -geometry 1x1\<+0+0 out_file.png
However, now I want to insert one pixel of spacing after each tile. I played with -tile-offset -1+0 for a bit but this would not change anything. Similarly, I could use -geometry 1x1\<+1+0, but this would introduce two pixels of spacing instead of one.
How can I do one pixel of spacing between tiles?

If the images are a known size then you can simply do 1 pixel larger in the -geometry switch. So if the images are 256x256 then use -geometry 257x256

Related

Splitting a region of an image into tiles

I have a set of images that are 4500px x 3000px in size.
Out of each of these images I need to extract a set of tiles in a 5 columns by 3 rows combination with each tile being 700px wide by 500px high.
What complicates the above is that the starting point for this needs to be at X:650 and Y:450 position from the top left corner of the image.
I have gotten as far as convert image.jpg -gravity NorthWest -chop 650x450 -crop 700x500 tile-%d.jpg
This gets me to a correct start position for creating the tile set but includes the rest of the blank area in the right and bottom edge of the image.
How do I go about solving this?
Within a single ImageMagick command you can crop the initial rectangle that contains all the tiles first, then crop that into the 15 output images. Try something like this...
convert image.jpg -crop 3500x1500+650+450 -crop 5x3# tile-%02d.jpg

Black line between 2 images while using append on imagemagick

I have two files;
1.jpg = 14000x2800 pixels
2.jpg = 2800x128 pixels
I use the following command:
...\convert.exe -auto-orient -quality 100 -append "1.jpg" "2.jpg" "out.jpg"
The goal is to merge the images together on the vertical axis, and it works great but now I need to add a straight horizontal black line between images (line's length should be the biggest file's length, meaning from left to right) while appending.
Is there any way to do that without a second command?
Easier description with MSPaint skills
Here's a way to do it:
magick 1.jpg 2.jpg -size "%[fx:u.w>v.w?u.w:v.w]x10" xc:black -swap 2,1 -append result.png
That says... load 1.jpg and 2.jpg. Define the width for the canvas we create next as "whatever is the wider of 1.jpg (referred to as u) and 2.jpg (referred to as v)" by 10 pixels tall. Create a black canvas that size. Now swap the order so that the canvas we just created is between the two images. Append all 3 images and save.
That gives you one of these, depending which one you load first:
If you want the unfilled, white background area beside the narrower image to be, say magenta, use:
magick -background magenta 1.jpg 2.jpg -size "%[fx:u.w>v.w?u.w:v.w]x10" xc:black -swap 2,1 -append result.png
Keywords: ImageMagick, image processing, wider, widest, taller, tallest, match existing image width, match height.

Rotate and crop an image, while keeping its original size

I have a JPG image with a known size of 3072x2048. Now I want to rotate that image by any degrees (e.g. 45), while keeping its original size. Thus - using ImageMagick on the command line - I first want to rotate, then crop the image, like this:
convert -rotate 45 -gravity center -crop 3072x2048 +repage original.jpg rotated-45.jpg
By using -gravity center I specify to crop the center part of the image, which is what I want. This operation produces four output images:
rotated-45-0.jpg
rotated-45-1.jpg
rotated-45-2.jpg
rotated-45-3.jpg
The first image rotated-45-0.jpg is exactly the final image I want to get. The other three I don't need. I could delete them, but I think it would be nicer to not generate these "extra" images in the first place. So I thought I could do it with this command instead:
convert -rotate 45 -gravity center -crop 3072x2048+0+0 +repage original.jpg rotated-45.jpg
This only produces one output image, however, now the top-left corner of the image is being cropped. So apparently the -gravity center is not used any longer.
Any ideas what I am missing here?
Using ImageMagick you can rotate an image any number of degrees while keeping the original canvas dimensions using "-distort SRT"...
convert original.jpg -virtual-pixel black -distort SRT 45 rotated-45.jpg
Use "-virtual-pixel" to specify how you want to handle the parts that were outside the canvas before the rotation. In this example I used "black". You can use black, white, background, tile, mirror, or none.

Imagemagick montage 3x3 spacing 1px

I want to merge 9 images using imagemagicks convert into 3x3 tiles with a 1px spacing between the tiles.
In my other, bigger version of the resulting image I have a spacing of 2px. To achieve this I've added a border of 1px to every image, and after the image has been created I'm using crop to strip the outer border.
Is there an easy way to get just 1px spacing between the tiles, unfortunately a border of 0.5px doesn't work.
The best.
Your method is similar to that used by the montage program, which has the same limitation that you found. In order to get 1px spacing between tiles, you will need a little bit more involved of a convert command. The method used here first builds the rows of the resulting image, then sticks them together, then cuts out border pixels that we don't want.
convert \( 0.png 1.png 2.png -splice 1x +append \) \
\( 3.png 4.png 5.png -splice 1x +append \) \
\( 6.png 7.png 8.png -splice 1x +append \) \
-splice x1 -append -chop 1x1 \
out.png
In more detail:
Each parenthesized subgroup says to add a column of width 1 to the left side of each image in the subgroup. The first image in the subgroup gets a column added, too, so we will clean this up at the end. We then append the images of our row horizontally, and then do the same for the second and third row.
After building our rows, we use splice to add a 1 pixel row to the top of our three rows, and append vertically.
At this point, we almost have the image we want, but we have a 1 pixel border on the left and on the top that we need to get rid of, so that is what that final -chop is for.
Hope this helps.

ImageMagick: montaging image from different-sized tiles

I'm developing a script to download images from tile-based image-hosting.
I downloaded tiles using wget and trying to use montage to compine them.
The problem is that I've got tiles with different sizes (last tile in row is more narrow than the others). Here is combine command:
montage $temp/*.jpg -tile $maxcolumn"x"$maxrow -geometry -1-1 -quality 100% merged.jpg
ImageMagick aligns tiles by grid and produces this image (see right and bottom sides).
image http://leftparagraphs.ru/!/merged.jpg
How do I fix this with montage?
Fixed by specifying "-mode Concatenate".
Also I have to run another instance of convert after montage to "-trim" resulting image.
This solution did not work for me. To combine two different height images into one, I first used the identify command to get the height of the largest image (1280 pixels):
identify large.jpg
Then I used the following command to resize the smaller image and combine it side by side with the larger one:
montage -tile 2x1 -geometry +0+0 small.jpg"[x1280]" large.jpg output.jpg

Resources