In fact thru the PDF sanitization and compatibility steps of Re/compress it is the ideal frontend for such cloud services. If you run or implement a new cloud service and have to deal with arbitrary PDFs of your users Re/compress can avoid many compatibility headaches. Select your image that you want to compress. After uploading, all images will automatically be compressed by this tool. Also, adjust the image quality like low, medium, high, very high as you wish. Finally, you can download compressed images one by one or download a zip file as you wish.
jpeg-recompress is an application that is used to re-encodeJPEG images to the lowest possible JPEG quality that still keeps the perceived visualquality to a certain standard. JPEG uses lossy compression, so there will always belosses when re-encoding the image. The goal is to do the compression while making theimage look practically the same after the compression.
There are three important parameters that can be adjusted when choosing how thisalgorithm works:
Unfortunately, these parameters are barely described anywhere. So in this post I’lltry to do that.
How jpeg-recompress works
jpeg-recompress compresses an image by lowering its JPEG quality, which is usuallyindicated by a number between 1 and 100. It does this by attempting to find a target,which is a number indicating the perceived quality of the image, e.g. 0.9999.Perceived quality is measured by algorithms such as SSIM. The JPEGquality for a given target is found by choosing two points, min
and max
, and thendoing a binary search between them. min
and max
are also JPEG quality numbers.
The quality parameter is simply a preset for the target value (this is for SSIM):
Quality | Target |
low | 0.99900 |
medium | 0.99990 |
high | 0.99995 |
veryhigh | 0.99999 |
The target can also be set manually with the --target
parameter.
Take, for instance, this image, which is 1.37 MB in size.
If I use jpeg-recompress with default settings (quality: medium, min: 40 and max: 95),I get this result:
We can see here that a search is being done between 40 and 95. First the span 40 to 95 iscut in half with 67 as the number in the middle. The number on the right end is the perceivedquality, as measured by SSIM, at the JPEG quality level listed on thesame line.
The target is 0.9999. Because 0.9998795 is less than 0.9999 the quality can beincreased by continuing the search with the upper half of the initial division, and a newsearch is done between 68 and 98. This continues until 0.999699 is found at JPEG quality 89.This is the value that will be used to compress the image.
The new image looks like this. The size is 867 kB. Good luck telling the difference betweenthis image and the one above.
Let’s continue with changing the quality to low. Low quality is a preset for target = 0.999.
Like before, the initial search conditions are between 40 and 95. The target that the searchlooks for is lower than before, so the optimal JPEG quality is now chosen to be 71.
If we want to lower the quality even further than low, we can either set target value manually,(rather than using a preset) or change the min
and/or max
values. As mentioned before, we canset the target manually with the --target
parameter. Lets try with the following settings:target = 0.90000, min = 45 and max = 95.
Because min
was set to 45 it refused to go below that, and the target was never reached. Let’s setmin
to 0 and try again:
So we can see that target
is the value jpeg-recompress searches for, while min
and max
aresaturations that it refuses to go below or above.
Let’s look at how min
and max
works more in depth. We will use the low quality preset again.
Changing min
to 60 and max
to 80, for example, will give this result:
We know that JPEG quality 71 was the optimal number for a target of 0.999, and 71 is stillwithin min
and max
, so the change didn’t help.
What happens if we decrease max
to a number below 71? For example max
= 50.
This will force jpeg-recompress to look for an optimal solution within the range 40-50. Thefound optimal quality is 51 (should have been 50, but there is a small bug in jpeg-recompress).The target quality was never found, because it reached the max limit before it was found.The image looks like this now and is 267 kB large.
jpeg-recompress can compress the image even further by reducing the max
value even more.min
is set to 1 and max
is set to 5. The search is now forced to run between two verysmall numbers.
The image looks like this now and is 43.7 kB large. By forcing the max
value to a smallnumber we are able to do fairly heavy compression. From the output above we can see thatthe search never came close to the target value. We got 0.911516 but were looking for0.9999. The image will therefore not have anything near the same perceived visual qualityas before, but will at least be compressed by a large amount.
Tl;dr
- quality sets the target presets for how good the perceived quality has to be whencompressing. It will directly influence the quality of the compressed image.
- target sets the target to a specific value if you need something else than thepresets. For example if low quality is not low enough.
- min sets the lower limit of the binary search. The quality of the compressed image willnever go below this value.
- max sets the upper limit of the binary search. The quality of the compressed image willnever go above this value + 1.
- to get heavy compression, below what the default values provide, you can either setthe target manually (below what low quality provides), or set
max
to a small number.
jpeg-recompress is an application that is used to re-encodeJPEG images to the lowest possible JPEG quality that still keeps the perceived visualquality to a certain standard. JPEG uses lossy compression, so there will always belosses when re-encoding the image. The goal is to do the compression while making theimage look practically the same after the compression.
There are three important parameters that can be adjusted when choosing how thisalgorithm works:
Unfortunately, these parameters are barely described anywhere. So in this post I’lltry to do that.
How jpeg-recompress works
jpeg-recompress compresses an image by lowering its JPEG quality, which is usuallyindicated by a number between 1 and 100. It does this by attempting to find a target,which is a number indicating the perceived quality of the image, e.g. 0.9999.Perceived quality is measured by algorithms such as SSIM. The JPEGquality for a given target is found by choosing two points, min
and max
, and thendoing a binary search between them. min
and max
are also JPEG quality numbers.
The quality parameter is simply a preset for the target value (this is for SSIM):
Quality | Target |
low | 0.99900 |
medium | 0.99990 |
high | 0.99995 |
veryhigh | 0.99999 |
The target can also be set manually with the --target
parameter.
Take, for instance, this image, which is 1.37 MB in size.
If I use jpeg-recompress with default settings (quality: medium, min: 40 and max: 95),I get this result:
We can see here that a search is being done between 40 and 95. First the span 40 to 95 iscut in half with 67 as the number in the middle. The number on the right end is the perceivedquality, as measured by SSIM, at the JPEG quality level listed on thesame line.
The target is 0.9999. Because 0.9998795 is less than 0.9999 the quality can beincreased by continuing the search with the upper half of the initial division, and a newsearch is done between 68 and 98. This continues until 0.999699 is found at JPEG quality 89.This is the value that will be used to compress the image.
The new image looks like this. The size is 867 kB. Good luck telling the difference betweenthis image and the one above.
Let’s continue with changing the quality to low. Low quality is a preset for target = 0.999.
Like before, the initial search conditions are between 40 and 95. The target that the searchlooks for is lower than before, so the optimal JPEG quality is now chosen to be 71.
If we want to lower the quality even further than low, we can either set target value manually,(rather than using a preset) or change the min
and/or max
values. As mentioned before, we canset the target manually with the --target
parameter. Lets try with the following settings:target = 0.90000, min = 45 and max = 95.
Because min
was set to 45 it refused to go below that, and the target was never reached. Let’s setmin
to 0 and try again:
Recompression Index
So we can see that target
is the value jpeg-recompress searches for, while min
and max
aresaturations that it refuses to go below or above.
Let’s look at how min
and max
works more in depth. We will use the low quality preset again.
Changing min
to 60 and max
to 80, for example, will give this result:
We know that JPEG quality 71 was the optimal number for a target of 0.999, and 71 is stillwithin min
and max
, so the change didn’t help.
Recompression
What happens if we decrease max
to a number below 71? For example max
= 50.
This will force jpeg-recompress to look for an optimal solution within the range 40-50. Thefound optimal quality is 51 (should have been 50, but there is a small bug in jpeg-recompress).The target quality was never found, because it reached the max limit before it was found.The image looks like this now and is 267 kB large.
Recompressions
jpeg-recompress can compress the image even further by reducing the max
value even more.min
is set to 1 and max
is set to 5. The search is now forced to run between two verysmall numbers.
The image looks like this now and is 43.7 kB large. By forcing the max
value to a smallnumber we are able to do fairly heavy compression. From the output above we can see thatthe search never came close to the target value. We got 0.911516 but were looking for0.9999. The image will therefore not have anything near the same perceived visual qualityas before, but will at least be compressed by a large amount.
Tl;dr
Recompress Tool
- quality sets the target presets for how good the perceived quality has to be whencompressing. It will directly influence the quality of the compressed image.
- target sets the target to a specific value if you need something else than thepresets. For example if low quality is not low enough.
- min sets the lower limit of the binary search. The quality of the compressed image willnever go below this value.
- max sets the upper limit of the binary search. The quality of the compressed image willnever go above this value + 1.
- to get heavy compression, below what the default values provide, you can either setthe target manually (below what low quality provides), or set
max
to a small number.