Cropping images into multiple equal Images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jnewbrough
Posts: 3
Joined: 2016-05-06T04:55:23-07:00
Authentication code: 1151

Cropping images into multiple equal Images

Post by jnewbrough »

I have a folder full of hundreds of images and am trying to crop each jpeg into multiple equal sized images. I have tried this but end up with excess little chips from the edges.

Each original image is 256 X 256 pixels and the goal is to crop these into 25 images that are 50 X 50 pixels. I keep getting 6 X 50 pixel images from the edge. Can anyone show me how to make this work correctly?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cropping images into multiple equal Images

Post by snibgo »

convert in.jpg -crop 5x5@ +repage out_%02d.png
snibgo's IM pages: im.snibgo.com
jnewbrough
Posts: 3
Joined: 2016-05-06T04:55:23-07:00
Authentication code: 1151

Re: Cropping images into multiple equal Images

Post by jnewbrough »

That almost works. It no longer gives me the small edge chips, but that is because it just re-sized the chips to take in the extra pixels. What I'm looking for is even 50 X 50 chips and just ignore the extras on the edges.

FOR %G IN ("*.jpeg") DO convert "%G" -crop 5x5@ +repage "output\%G"
jnewbrough
Posts: 3
Joined: 2016-05-06T04:55:23-07:00
Authentication code: 1151

Re: Cropping images into multiple equal Images

Post by jnewbrough »

It isn't pretty, but I got it.

FOR %G IN ("*.jpg") DO convert "%G" -crop 250x250+0+0 "output\%G"

FOR %G IN ("*.jpg") DO convert "%G" -crop 5x5@ +repage "output\%G"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cropping images into multiple equal Images

Post by snibgo »

If you want to crop each image into a single 250x250, then chop that into 25 off 50x50 pieces, you need only one for loop and only one convert:

Code: Select all

FOR %G IN ("*.jpg") DO convert "%G" -crop 250x250+0+0 +repage -crop 5x5@ +repage "output\%G"
I'm not sure if the first "+repage" is needed.
snibgo's IM pages: im.snibgo.com
Post Reply