jottr
jottr

Reputation: 3293

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

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?

Upvotes: 30

Views: 17159

Answers (1)

dank.game
dank.game

Reputation: 4709

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

Upvotes: 44

Related Questions