Categories
How To Article Technology - Tips Website Design

How to Optimize JPEG (JPG) images for Good Quality and Small Size

How to Optimize JPEG (JPG) images for Good Quality and Small Size

The image compression techniques have their origin in the necessity of reducing the size of the file used to store the image, which is huge when compared to storing text (a 800×600 24 bit color uncompressed image needs 1440000 bytes or 1.37 MB). One of the most popular formats is JPEG (which uses files with JPG or JPEG extensions), which can achieve compression ratios of 10:1 with almost no perceived loss of the image quality.

Depending of the program that you use for saving JPEG images, there are available some options for adjusting the compression of the image. In this article I’ll try to explain how to adjust that options and optimize the ratio between image quality and file size. It’s important take into account that some images are more suitable than others for JPEG compression.

Basic compression options

The two basic options that are almost always present in every “Save JPEG” dialog are the compression/quality of the image, and the standard/optimized/progressive formats.

Both compression and quality refers to the same parameter but one is the inverse of the other (e.g. in a percentage-based scale 35% compression is equal to 65% quality). Depending of your program of choice you’ll find either, but the result is the same: the more compression, the lesser image quality. The proper setting for this parameter depends of the image quality or file size you need/want to obtain, getting the best ratios with 50%-85% of image quality (equivalent to 50%-15% compression).

The standard (baseline) and optimized (baseline optimized) settings provides the same image quality but the optimized format provides a 2%-8% reduction of the image file size, so there is no reason for not use always this setting when not using the progressive format. The progressive format also provides the same quality, but offers an alternate method of displaying the image while it is downloaded, at the cost of a slight increase in the file size.

Advanced options

Apart from that options, some programs like Corel PhotoPaint, Paint Shop Pro and IrfanView (this one is freeware) allow choosing the type of image subsampling, also called downsampling. The subsampling ratios according to the spec are 4:4:4 (no subsampling), 4:2:2 (standard subsampling) and 4:1:1 (worst quality, rarely used). Adobe Photoshop also contemplates this option but it’s adjusted automatically depending on the quality level selected: it applies subsampling for Medium and Low levels and uses no subsampling for Maximum and High.

While the standard subsampling is usually adequate for most images, providing an good ratio between image quality and file size, there are some situations in which using no subsampling (4:4:4) provides a noticeable increase in the image quality, even if you use a higher compression ratio in order to maintain the file size. The most notable cases are when the image contains some portions with fine details, like text over an uniform background, and images that contain almost-flat colors.

Examples

JPEG image, 15% compression (85% quality), standard subsampling (4:2:2), 8822 bytes.

JPEG image, 25% compression (75% quality), no subsampling (4:4:4), 8096 bytes.

You can see than even with more compression (in order to achieve a similar file size) using no subsampling (4:4:4 format) produces sharper images.

Further Optimization

Almost all digital cameras store by default EXIF data in the pictures taken with them. This data include information about the camera configuration and conditions at the time of the photo shot. This information usually takes a lot of space, so make sure that saving this data is disabled in your graphical application when optimizing JPEG files (e.g.: in a test, an 800×600 JPEG picture saved at 75% quality was reduced from 114 KB to 51 KB after stripping the EXIF information).

IrfanView, a freeware graphic viewer/converter, has a plugin for JPEG lossless transformations that allows stripping this data (and other similar like IPTC information) from a JPEG file without recompressing the image itself. In this way you can remove the unnecessary information while maintaining the original image quality.