Methods with Losses: Resizing, Color Detection, and Other Techniques
Previously in the PDf Optimization In-depth Series.
- Introduction to the Optimization of Existing PDF files: Methods
- Lossless Methods: Optimization of Document Content
- Lossless Methods: Compression of Streams and Fonts
- Methods with Losses: JPEG 2000 and JBIG2
This article was originally published on the GdPicture blog.
Resizing images
Resizing images can provide significant gains in occupancy.
For example, decreasing unnecessary high resolutions can dramatically reduce the file size without affecting the viewing experience. But sometimes it is also a pretty destructive approach.
There exist many sophisticated resizing algorithms, but it is rare to obtain a result that does not significantly degrade the perception of the image.
An interesting alternative may be to resize only the chrominance channel.
In the sub-sampling method of chrominance, certain color spaces make a separation between brightness and color information.
Human vision is less sensitive to color than to brightness. This permits to reduce, or undersample, chrominance information without degrading the perceived quality of the image.
The resampling process recreates an image from scratch. The destination image with the given dimensions is created, and the values for each pixel are computed based on the source image. Chroma subsampling method favors less resolution for chroma information than for luma information in the resulting image.
The JPEG and JPEG2000 compression schemes[link to article 4] enable the usage of this chrominance downsampling method.
Feel free to try it with GdPicture.NET here.
The average space saved by this method is 20%. However, 60% of images encoded in JPEG do not use it.
Color detection
Automatic color detection detects the original color of images scanned in color mode and converts the black and white or grayscale ones to the appropriate bpp (bits-per-pixel) encoding.
This approach, although destructive, produces excellent results in terms of quality and compression rate improvement. It results in very fast and unattended optimizations of image and PDF archives.
We provide this technology in our SDK, you will find the related documentation here.
Other techniques
And finally, there are a couple of other methods to reduce the file size of images:
Reduction of the graphic objects description
It is useful especially for the figures generated from the CAD system.
One can try to delete points on paths, to reduce the number of useless decimals in floating-point numbers, to convert smoothed lines into curves, etc.
Flattening of transparency
Transparency in PDF files points to transparent objects on a page.
It is typically used for shadow effects, to make text readable while covering it with an image and more.
The process of flattening incorporates transparency into the corresponding artwork by splitting it into vector areas and pixelated areas. It may be necessary when printing, saving or exporting the document into other formats that don’t support transparency while ensuring, for example, the print quality as expected.
Transparency flattening cannot be undone once the file is saved.
That’s all for today!
If you don’t have time to search our reference guides, we have grouped the code samples for the described approaches in this blog article.
Our next and last article will be about MRC compression, so see you then!
Loïc & Elodie