Basic Cropping

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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

First of all Read in your image BEFORE cropping. Saves a lot of trouble
with argument ordering.

The ! is a viewport crop. It does NOT force the crop to be a specific final size
and is NOT designed for use with tiles. I believe it is ignored for tile cropping.

next add a +repage afetr the crop, as you don't seem to need to preserver the offset of the crops on the virtual canvas. Doing it before the crop may also be useful if the image could contain a virtual canvas that you don't care about. That I don't think is a an issue for PCX format.

As you are asking for a 200x200 pixel image crop will try to return 200x200 pixel images, but if it can't, it can't. As such expand your images back to
200x200 using a fast -extent operator with the same size (adds a black fill)

For other colors, you may have more difficultes and may require you to -slice on a larger edge and re-crop it again!

Here is the fixed command...

Code: Select all

convert Map.pcx -crop 200x200 +repage -extent 200x200 -quality 75  slice%d.jpg
ALL the above is exampled and detailed in IM Examples, on the Cropping and Bordering Page
http://www.cit.gu.edu.au/~anthony/graph ... ick6/crop/
Read it!
Another issue is that i am not happy with the name format of the output's slices. I'd rather like to have something along the lines of slice<xseg><yseg>.jpg


Actually a lot of people would like that, and currently the only solution I have involves preserving the vitrual canvas page information removed by the +repage command above, saving the images using a file format that understand virtual canvas offsets (like PNG), and renaming the images basied on some mathematics of that offset. After that the image can be saved in the format desired using "mogrify".

I won't publish the current script version however as it is too specialized (in math and image handling) for jigsaw puzzle pieces, rather than crop tiles.

A much more general script for crop tile renaming is needed.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply