Web developers and designers usually have to optimize a number of images. So individually optimizing the images one by one is a pathetic process as the task is time taking and mundane. Why only web developers, even casual users can optimize multiple images at a time before uploading it on the web fast. It would be better if there was a way to optimize them simultaneously. Here is a convenient way how to compress image files inside a folder using command line.
If you have a computer with Windows OS then it would be better to install Cygwin. The bash shell makes it easy to perform an operation on multiple files simultaneously in Linux or Mac systems.
Steps to Compress Multiple Images Files Inside a folder:
- Install Cygwin on your Windows computer.
- Switch to the /cygdrive/c/ folder using the command: cd /cygdrive/c/
- Use the cd and ls commands to figure out where you are currently in, and navigate into the image folder that you want to manipulate.
- Run the following command:
for f in *.jpg; do convert -quality 80 $f $f; done
Compress Single Image File Using command Line
Use the following command to optimize a single image file:
convert -quality 80 image1.jpg image2.jpg
- -quality parameter determines the level of compression for the image file. Lower the value, more is the compression, but lower is the quality of the image file.
- The first name (image1.jpg) is the name of the image file to be compressed.
- The second name (image2.jpg) is the name of the compressed file that you wish to save it as.
Make sure to backup all the images before compressing.