Is it possible to crop a JPEG image without losing quality or recompressing the remaining part of the image?
-
1I don't think cropping a image loses the quality of it.– ekcloneJul 7, 2015 at 11:21
-
5Not in itself. However, if the image editor you are using is not smart enough, when it comes to saving the cropped image, it could easily re-compress an already compressed image, which would be needless and result in image loss. I'm wondering if it's possible avoid this.– Dan StevensJul 7, 2015 at 12:14
-
1Could you tell me what kind of software you use? for image editing– ekcloneJul 7, 2015 at 12:56
4 Answers
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.
-
The wiki says "cropping at image block borders (every 8×8 or 16×16 pixels)." Does the tool limit you to these boundaries in order to make this possible? I guess from your note about mitigating lossage in other programs that the answer is "yes" (?)– YorikJul 7, 2015 at 16:06
-
1Sometimes the multiple must be 16 instead of 8. JPEG allows subsampling of the color information, which means the 8x8 blocks for those color components will actually cover 16x16 pixels. Jan 12, 2017 at 17:03
-
1@MarkRansom right, thanks. I expanded the answer to mention "or 16" Jan 13, 2017 at 1:59
-
-
@LuisA.Florit you could run ImageMagick's "identify -verbose" or some other JPEG examination tool and look for the "sampling factors". May 16, 2017 at 20:33
FreeVImager can do this with nice GUI.
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.
-
Hmm... I tried this and the current version matches your illustration. But I can't find an "accept" or "done" control to use after moving the rectangle to the desired position.– JDługoszMay 3, 2017 at 10:22
-
@JDługosz just press Enter :) (the tip in status line) Also, author is communicable and gladly responds emails. You can tell him ;-) May 5, 2017 at 21:10
-
2Wow, house of my sister in Stack Exchange :) . Thanks, if I use FreeVimager, I can crop big-size
jpg
; if I use GIMP, I can't do it. Feb 14, 2018 at 12:50 -
This program is snapping the bottom and right sides to iMCU boundaries despite it being unnecessary and restrictive. IrfanView worked better for me.– mm201Oct 16, 2019 at 20:30
-
The cropped image is bigger in size then the original image, using the Lossless Crop toll in FreeVImager 9.9.10. So it's useless... Sep 15, 2020 at 20:58
If you are using Photoshop® then I don't believe that the image compresses when it crops. The compression happens when you resave the document as a JPG. It is always best to start with the highest lossless uncompressed image format you can such as .NEF, .BMP... others (?) As the saying goes, poop in poop out.
-
2I don't think it is as you think. I think Photoshop can't do crop without recompression.– RoyiNov 2, 2019 at 18:34
-
@Royi - no. Photoshop can crop the jpeg without recompression, the problem is when you resave it as jpeg. Compression will be added again. If you export as PNG instead, you can avoid this issue entirely, since PNGs are lossless. 2 days ago