Splitting a region of an image into tiles - imagemagick

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

Related

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.

How to crop or chop the images at the L shaped corner edges with imagemagick

[]
I use imagemagick -6 for conversion.
I have an image like above. Actual image resides in the rectangular area. I need to remove the L shaped corner edges as you see. I tried with lots of options available in : https://imagemagick.org/Usage/crop/#splice . As crop/chop and shave options applicable symmetrical to both sides. I was thinking If I can just splice the un-wanted L shaped areas.
I tried with convert -background blue -gravity East -splice 10x10 +repage but of no luck. It basically adds a cross in horizontal and vertical in the middle of the image. Please advise if it possible just to erase/chop a particular area. e.g. some portion of an edge and not the complete edge. The reason here is I don't want to chop-off any part of rectangular shape but the L shapes above and below. Basically looking for removing/splicing with white color just L shaped one corner at a time if possible using Imagemagick-6. As I don't know about the pixel size in advance. I don't know if one liner solution will work.
Many thanks!
I think you mean this:
magick image.png -crop 305x365+232+58 result.png

Put image on top of other image, but resize to fit first

I have two pngs. One is of unknown size (but always square), the 2nd is 1024x1024 and mostly transparent. I want to put the 2nd on top of the first, but first scale it down to the size of the first.
E.g. image1.png is 100x100, overlay.png is 1024x1024. The resulting image size is 100x100 with the overlay scaled down to 100x100 and put on top of the source file.
So far I got this:
magick convert ~/Downloads/Test\ icon.png res/drawable/icon.png -gravity center -composite ~/result.png
But the resulting image is 1024x1024 and the original is tiny somewhere in the center.
This will read in both images, resize the second to fit within the dimensions of the first, then composite the second centered over the first.
magick img1.png img2.png \
-resize %[fx:u.w]x%[fx:u.h] -gravity center -composite output.png
If used in Windows, that continued line backslash "\" should be changed to a caret "^". If used in a Windows BAT script, the single percent signs "%" need to be doubles "%%".
EDITED TO ADD: The way that works is this... Two images are read into the command. The FX expressions "u.w" and "u.h" stand for the width and height of the first image. So to "-resize" first image to its own dimensions doesn't change it, of course. And the second gets resized to fit within the dimensions of the first.

convert debian-logo.jpg -crop 16x16-16-16 debian_crop.jpg error

I want to cut an image called debian-logo.jpg with the following command:
convert debian-logo.jpg -crop 16x16-16-16 debian_crop.jpg
But for some reason there is an error. Could someone tell me how to fix it?
How big is your input jpg? Using negative crop offsets in ImageMagick only works with -gravity center (and sizes larger than 32x32). Otherwise, the crop will be off the image bounds for any other gravity setting. Crops are always relative to the gravity setting, which defaults to the -gravity northwest. See http://www.imagemagick.org/Usage/crop/#crop_gravity
If you want to crop inside the image with an offset, then the crop offsets need to be positive and will be cropped inside using positive offsets, even with -gravity south, east etc. The positive offset move inward relative the corner or side indicated by the gravity setting.
Are you trying to extend and pad the image in some direction with the crop. If so, then use
convert debian-logo.jpg -background black -gravity northwest -extent 16x16-16-16 debian_crop.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