File size can be a real issue with photos. Usually, the higher the quality and dimensions of an image, the higher the file size and large file sizes result to slower upload and download times and take up more precious storage space. So what we want is to decrease the file size of photos and there are a number of methods we can try to do this.
First and foremost, format of the image plays a huge role in the file size. If the image is made up of geometric shapes, such as logos or texts, it is usually better to go with Vector Image format. If the image is complex, such as a photograph, then Raster image format should be preferred.
Vector images can have their file sizes reduced by using applications like ‘svgo’ which removes unnecessary information from the file.
In case of Raster images, which consist of a grid of pixels, it is usually a matter of trade off between image quality and file size. Raster Images can be compressed in Lossy or Lossless formats and image compression is usually a combination of both. If you require detailed, high resolution images then PNG format is preferred. PNG format uses only Lossless compression and that is why they have a comparatively higher file size. On the other hand, formats such as JPEG use a combination of both Lossy and Lossless compression so it is possible to obtain a middle ground where the quality of the image is acceptable and the file size is relatively small as well.
There is no specific program or tool that applies to each and every image and image format so given below are some compressors you can use to compress your photos.
|jpegtran||optimize JPEG images|
|optipng||lossless PNG optimization|
|pngquant||lossy PNG optimization|
|gifsicle||create and optimize GIF images|
You can mess around with the options with these programs and find what suits your need best. You could have a mildly Lossy image with a reasonable file size or a high quality image with a big file size or even a low quality image with a low file size.
Another way of optimizing raster images is removing unnecessary metadata which takes up a considerable amount of space. Resizing the image on the server to match as closely as possible the display image also reduces the chances of file size increasing.
So, Photo Optimization is basically about finding the right spot in the tradeoff between file size and image quality and if you’ve followed the steps described in this article then you should have a successfully optimized image.