Some GIMP users who follow tutorials written for Adobe Photoshop are sometimes confused when they see statements like “Save your image using quality 8 or 9 in order to get good results” because this obviously does not match the scale from 0 to 100 used by GIMP (and other software based on the IJG JPEG library).
While working on some improvements for GIMP’s JPEG plug-in, I investigated the compression levels used by various programs and cameras. The analysis of several sample images allowed me to build the following mapping table (slightly updated since I posted a similar message to the gimp-web mailing list in August):
- Photoshop quality 12 <= GIMP quality 98, subsampling 1×1,1×1,1×1
- Photoshop quality 11 <= GIMP quality 96, subsampling 1×1,1×1,1×1
- Photoshop quality 10 <= GIMP quality 93, subsampling 1×1,1×1,1×1
- Photoshop quality 9 <= GIMP quality 92, subsampling 1×1,1×1,1×1
- Photoshop quality 8 <= GIMP quality 91, subsampling 1×1,1×1,1×1
- Photoshop quality 7 <= GIMP quality 90, subsampling 1×1,1×1,1×1
- Photoshop quality 6 <= GIMP quality 91, subsampling 2×2,1×1,1×1
- Photoshop quality 5 <= GIMP quality 90, subsampling 2×2,1×1,1×1
- Photoshop quality 4 <= GIMP quality 89, subsampling 2×2,1×1,1×1
- Photoshop quality 3 <= GIMP quality 89, subsampling 2×2,1×1,1×1
- Photoshop quality 2 <= GIMP quality 87, subsampling 2×2,1×1,1×1
- Photoshop quality 1 <= GIMP quality 86, subsampling 2×2,1×1,1×1
- Photoshop quality 0 <= GIMP quality 85, subsampling 2×2,1×1,1×1
The quality settings in Adobe Photoshop include not only the compression factor that influences the quantization tables, but also the type of chroma subsampling performed on the image. The higher quality levels use no subsampling, while the lower ones use 2×2 subsampling. The strange transition between Photoshop quality 6 and 7 (quality 6 having a higher equivalent IJG quality than 7) can be explained by the difference in subsampling: since quality 6 has less color information to encode, the size of the file will be smaller anyway, even if more coefficients are preserved in the quantization step.
You may also be surprised by the fact that the default GIMP JPEG quality level (85) matches the lowest quality offered by Photoshop: quality 0. This makes sense if you consider that the default “Save” offered by Photoshop is designed for high-quality images, so the losses should be minimized. But if you want to save images for web publishing, then Photoshop has a separate “Save for Web” feature that can save images using lower quality levels:
- Photoshop save for web 100 <= GIMP quality 98, subsampling 1×1,1×1,1×1
- Photoshop save for web 90 <= GIMP quality 96, subsampling 1×1,1×1,1×1
- Photoshop save for web 80 <= GIMP quality 93, subsampling 1×1,1×1,1×1
- Photoshop save for web 70 <= GIMP quality 90, subsampling 1×1,1×1,1×1
- Photoshop save for web 60 <= GIMP quality 85, subsampling 1×1,1×1,1×1
- Photoshop save for web 50 <= GIMP quality 86, subsampling 2×2,1×1,1×1
- Photoshop save for web 40 <= GIMP quality 79, subsampling 2×2,1×1,1×1
- Photoshop save for web 30 <= GIMP quality 74, subsampling 2×2,1×1,1×1
- Photoshop save for web 20 <= GIMP quality 70, subsampling 2×2,1×1,1×1
- Photoshop save for web 10 <= GIMP quality 60, subsampling 2×2,1×1,1×1
This mapping between Photoshop and GIMP quality levels for JPEG is not exact and is intentionally pessimistic for GIMP. There is some safety margin, so it is possible to decrease the GIMP quality level a bit and still get a file that is as good as the one saved by Photoshop.
Reminder: if you think that you will need to re-edit an image later, then you should never save it only in JPEG format. Always keep a copy in XCF format (GIMP’s native file format) so that you can edit it without losing any additional information.
Another reminder: using a JPEG quality level below 50 or above 98 is not a good idea. Saving a JPEG image using quality 99 or 100 is just a waste of disk space. You should use a different file format instead (such as PNG or TIFF). And below quality 50, you lose so much that it would be better to rescale your image and use a lower resolution before trying to compress it further.
I’m working with GIMP and so far it seems that Photoshop’s jpeg compressing achieves better quality with less file size than GIMP (which I assume uses libjpeg).
Is it because Photoshop uses a better algorithm? Perhaps there are any alternatives to libjpeg which can give a better size/quality ratio?
Do you have any sample files that could be used for comparing the quality/size ratio of both programs? So far, I came to the opposite conclusion. But maybe I am biased…
Anyway, using a different library than libjpeg would not change much: Photoshop cannot use a better (or worse) algorithm, because the JPEG compression algorithm is standardized and has to be implemented in the specific way if you want the files to be readable by any JPEG viewer.
The differences that can be observed between both programs are not related to the algorithm, but to the quantization tables that are used for the JPEG compression. These tables define how much of the original image is kept when saving (specifically, the divisors in these tables influence how many DCT coefficients are kept). Each table contains 64 numbers and is included directly in the JPEG file because it is needed for decompressing the file later. There are usually 2 or 3 quantization tables in the file: one for luminance and one or two for chrominance.
When you select a given “quality level” in GIMP (libjpeg) or in Photoshop, you are asking the program to generate the quantization tables that have been associated with that quality level by its developers. Different programs use different tables, but they usually have many similarities. That’s why I created the tables included in this article: they allow you to find the quantization tables that are similar in both programs.
Considering how JPEG compression works, I would be very surprised if you could find some images that produce better results in Photoshop than in GIMP. What happens is usually the opposite: GIMP saves JPEG files that are smaller than with Photoshop but have the same (or better) quality. One of the simple reasons for that difference is that Photoshop includes more metadata by default.