Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Magick: Image optimization for websites

I have a camera which produces photographs of 3008x2000 pixels. I use Image Magick to scale and resize the photos to be put up on my website. The size of the images I am using on the website is 602x400. I use this command to reduce the size:

convert DSC_0124.JPG -scale 20% -size 24% img1.jpg

This produces an image which is 602x400 pixels in size. But the file size will be always above 250KB. More images on a single html page means the page will be heavier and loading time will be longer. Are there any features in image magic that will help me to keep the file size as small as possible, possibly, below 100KB. But the image size should be the same, that is, 602x400px. I have achieved similar optimisation with SEAMonster tool for MS Windows. As it doean't have a commandline alternative, it wouldn't be of much help when there are hundreds of images to be converted.

like image 561
nixnotwin Avatar asked Aug 13 '11 03:08

nixnotwin


People also ask

What is image optimization for the web?

Image optimization is about reducing the file size of your images as much as possible, without sacrificing quality, so your page load times remain low. It's also about image SEO. That is, getting your product images and decorative images to rank on Google and other image search engines.


2 Answers

Use command as Delan proposed with additional "-strip" flag to remove EXIF data, this have reduced the size of some of my images drastically. Here is a bash script for unix platforms, but you can use the second part only for individual images.

for X in *.jpg; do convert "$X" -resize 602x400 -strip -quality 86 "$X"; done

This will convert all images in the directory.

like image 100
Ross Avatar answered Sep 23 '22 06:09

Ross


Use -quality to set the compression level:

convert DSC_0124.JPG -scale 20% -size 24% -quality [0..100] img1.jpg
like image 23
Delan Azabani Avatar answered Sep 23 '22 06:09

Delan Azabani