ImageMagick: montaging image from different-sized tiles - image-processing

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

Related

Blur part of an image only

I would like to blur only a part of an image. The part to blur is always rectangular, so that I can easily use the following command:
magick source.jpg -region 1000x1000+0+500 -blur 0x20 result.jpg
This works, but is pretty slow for large images. Since I have to process thousands of files again and again, this will simply take too long.
Therefore, I decided to do the blurring by downscaling and upscaling the image back to the original size. However, since this will blur the full image, I have tried to accomplish the task using the following steps:
take the original image as background
create a copy of the original image
blur the copy using down-/upscaling
crop the desired region from the blurred copy
compose the original and the blurred&cropped copy
I am already pretty close (I hope), but when composing the two images, the cropped image will always be positioned in the top-left corner of the original image - instead of the original position from the source image. This is my current command:
magick source.jpg ( -clone 0 -resize 5% -resize 2000% -crop 1000x1000+0+1000 ) -composite result.jpg
I have read in the documentation that the original canvas size will be retained when using the -crop operation, and that this size and position will be used when using -composite. However, this doesn't seem to work in my case. Does anyone have an idea why?
I have tried to use -repage, -extent and other options to define the size and position of the cropped image, but to no avail so far.
I would try -flatten in your command as that is used for layers.
You can do it with a mask image (of any shape) in ImageMagick. Though I am not sure if that will be faster than your scaling method.
Input:
Mask:
(note: blurring occurs where mask is black)
magick lena.jpg -write-mask mask.png -blur 0x3 +write-mask lena_blurred.png
Result:

How to fit multiple images in a page optimally using ImageMagick

Suppose I have a bunch of images in a folder with different sizes. The goal is to fit images in a number of pages (e.g. A4) in a way that the whitespace is minimal. There shouldn't be any compression or resizing involved. It is acceptable that some images would be rotated.
Here is what I came up with but doesn't try to "fit" images in any way:
montage *.jpg -mode concatenate -tile 2x2 -page A4 -geometry +20+20 out.pdf
Is it possible using imagemagick and montage switches?
I guess the computational geometry algorithm should change the 2x2 and +20+20 part of the command above, right?
In ImageMagick 7 (7.0.10-23 or higher), there is a new feature for doing collages called Ashlar. But it resizes to fit all the provided images into the space allocated.
See https://imagemagick.org/script/formats.php#pseudo
magick *.jpg -define ashlar:best-fit=true ashlar:canvas.png[1000x1000+5+5]
The [1000x1000+5+5] specifies the output dimensions and the minimum spacing in x and y between images.
Here is A4 size result:
magick *.jpg -define ashlar:best-fit=true ashlar:canvas2.jpg[595x842++0+0]

Imagemagick Crop image borders for lot of images with different sizes

I have a lot of images. Size of images are different.
I need to write the one imagemagick commandline operation to crop the borders of each image (for example, 10px of each edge).
Basic usage of -crop reuire to know the image geometry - it's not usefull.
Use -shave
convert montage.png -shave 10x10 montage.png

imageMagick not creating exact number of tiles

I am creating an image having dimension 357x357 using imagemagick and then creating 100 tiles using crop command but it only crops first 10 images
here are the commands
convert -size 357x357 xc:skyblue 1.jpg
convert -crop 10x10# 1.jpg 1-slices.jpg
first command creates image with 1.jpg having dimension 357x357 and second command is for creating 100 tiles but it only creates 10 tiles and returns.
Here are the tile names it created
1-slices-0.jpg ......... 1-slices-9.jpg
Why it is not generating 100 tiles?
Any help will be really appreciated.
The # applies the evenly spaced crop along one dimension (apparently). Best thing I can think of is to isolate each plane into a separate -crop command
convert 1.jpg -crop x10# -crop 10x# 1-silces-%d.jpg

How to insert one row spacing between tiles in a tiled image using 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

Resources