Advertisement


How to crop a JPG without recompressing?


Question

Is it possible to crop a JPG image without losing quality/recompressing the remaining part of the image?

2017/01/12
1
13
1/12/2017 10:50:00 AM

Accepted Answer

FreeVImager can do this with nice GUI. Lossless crop menu Lossless crop operation

It also can do lossless rotation of JPEGs (90 deg rotations are loseless). It's FOSS, so if you're on Linux, it's worth getting Wine for one.

2017/01/12
5
1/12/2017 6:39:00 AM

Lossless cropping of a JPEG image is possible using the "jpegtran" application that comes with libjpeg; see https://en.wikipedia.org/wiki/Libjpeg.

Quoting from "man jpegtran" on a system where jpegtran is installed:

.. lossless crop is restricted by the current JPEG format: the upper left corner of the selected region must fall on an iMCU [8 or 16] boundary. If this does not hold for the given crop parameters, we silently move the upper left corner up and/or left to make it so, simultaneously increasing the region dimensions to keep the lower right crop corner unchanged. (Thus, the output image covers at least the requested region, but may cover more.)

With other image-editing software you can minimize the loss by ensuring that the cropped area has dimensions that are multiples of 8 and is located with offsets being some multiple of 8 (or 16, if the colors were subsampled) from the upper lefthand corner of the original image, and that the compression "quality" is the same as that of the original image.