Get coordinates from -trim

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
Ilya87
Posts: 1
Joined: 2011-07-27T06:08:24-07:00
Authentication code: 8675308

Get coordinates from -trim

Post by Ilya87 »

I use -trim with -fuzz options to autocrop a batch of jpg. But this results in loss of quality.
So is there any posibility to direct cropping coordinates to jpegtran -crop WxH+X+Y and make lossless cropping?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Get coordinates from -trim

Post by fmw42 »

you would have to use JP2000 in lossless mode (Jasper delegate library).

You could try adding -quality 100, but jpeg even at -quality 100 will still be slightly lossy.

What does this have to do with your title about getting coordinates from the trim? To do that you would need to save the result to png without using +repage after the trim. Then the verbose information for the file will contain the virtual canvas geometry with offset.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Get coordinates from -trim

Post by anthony »

WARNING: jpgtrans or any other lossless JPEG operation on image data itself is limited to cell boundaries. That is you can only crop to the cell dimensions, and not to pixel level. as such you are limited to either 8 or 16 pixel increments (depending on sub-sampling).

Actually breaking a 'cell' will require a decoding and re-encoding of the cells along the edges, and that only if you don't want to translate the image to a new origin.

See IM Examples, JPEG, lossless processing
http://www.imagemagick.org/Usage/formats/#jpg_lossless
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply