Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using imagemagick how can i slice up an image into several separate images?

Tags:

Please consider following example:

enter image description here

The source image consists of 6 areas that need to be sliced up into 6 separate images.

How can I get the desired output using imagemagick. I tried to understand a possible solution presented in the imagemagick examples, but failed to transfer it to my specific problem.

What would be a way of solving this problem preferably in a one-liner? Since all the areas which i want to slice have the same size, but only differ in their offset, is there a way to somehow pass a preset area size, and then simply add the xy-offset for each area?

like image 485
jottr Avatar asked Mar 09 '12 15:03

jottr


People also ask

How do I crop an image in ImageMagick?

To crop an image using ImageMagick, you need to specify the X and Y coordinates of the top corner of the crop rectangle and the width and height of the crop rectangle. Use the mogrify command if you want the images to be replaced in-place or use the convert command otherwise to make a copy.

What can you do with ImageMagick?

Use ImageMagick® to create, edit, compose, or convert digital images. It can read and write images in a variety of formats (over 200) including PNG, JPEG, GIF, WebP, HEIC, SVG, PDF, DPX, EXR and TIFF.


1 Answers

If each area has the same amount of padding around it, you can use the @ operator.

This cuts an image into 6 sections, 2 per row, with 40 pixels of horizontal padding and 20 pixels of vertical padding excluded from each section:

convert image.png -crop 2x3-40-20@ +repage +adjoin tile-%d.jpg 
like image 80
0eggxactly Avatar answered Oct 06 '22 00:10

0eggxactly