Whenever uploading a picture to the internet, compressing it is necessary. If an image is uncompressed, it will take a longer time to upload or download. Also, when using email, a lot of email servers have a limit on how much data one can put in an email. Due to all these reasons, image compression becomes a necessity while sharing it over the internet, especially on slower network connections.
There are several compressing algorithms, and most of these can be put into two groups — lossy and lossless. Both these algorithms use encoding methods like Huffman encoding to reduce the size of an image.
An image consists of pixels. The main aim of a compression algorithm is to reduce the space required for storing this information. While JPEG is saved via a lossy algorithm, PNG uses a lossless one. Below, we’ve briefly explained the difference between the two algorithms before moving on to a comparison of the two image formats.
Lossy algorithm
A lossy algorithm, also known as an irreversible algorithm, compresses the image in such a way that the old image cannot be recovered. It takes a defined group of pixels — array size is based on the compression ratio — and then substitutes a single pixel value for that array. This decreases the size of the image, but the original information is lost and hence can’t be recovered.
When a lossy algorithm with a high compressing ratio is used, a picture looks pixelated. Due to the loss of information, the image quality decreases. A lossy algorithm can achieve higher compression compared to a lossless algorithm.
Lossless algorithm
A lossless algorithm, as the name suggests, does not cause any loss of Information. Hence, it does not reduce image quality. An image compressed using a lossless algorithm can be used to get back the original picture. This algorithm is mostly applied to texts. Due to the information preservation property of the algorithm, the compression ratio is lower compared to a lossy algorithm.
Also read:Â DSLR vs Phone Camera: Do megapixels really matter?
JPEG VS PNG
JPEG (Joint Photographic Expert Group) is a widely used compression algorithm for pictures. It uses a Discrete Cosine Transform (DCT) to perform the compression. This algorithm checks the pixels that are similar and then mixes them, thereby lowering the image size, and also quality, to some extent.
EXIF (Exchangeable Image File) is a standard feature in JPEGs which records metadata such as time, location, date, among others, on the file and comes handy to photographers. JPEG has, by and large, a compression ratio of 10:1, which means that you can convert an image of 10 MB size to roughly 1 MB by exporting it through JPEG. Due to these reasons, JPEG tends to cause blurring of text also knows as anti-aliasing
PNG (Portable Network Graphics) is mostly used for compressing images with transparent backgrounds. JPEG doesn’t support transparent backgrounds. It uses the LZW algorithm for compression. This algorithm is a two-stage process and stores bits of information in the dictionary or a codebook alongwith the shortcodes.
When this information is repeated, the shortcodes are used instead of the long codes. Now the file is small and also matches the quality of the previous file. Due to these reasons, most of the screenshots are saved in PNG format.
Which one should you choose?
Both formats have their advantages and disadvantages. The decision to choose a compression algorithm should be based on the use case. If you’re uploading the images to the web and they aren’t getting compressed while doing that, it’s recommended to use JPEG images as they’re relatively smaller in size, which translates to better page load times. However, if you’re saving the image for personal use or a presentation, PNG is the recommended extension.
Also read:Â Camera Optics 101: Prime lenses and their benefits