Saturday, April 27, 2013

6:45 AM





In this post, you can know that How to Compress a Folder of Images Easily from the Command Line It's simple and easy.



If you are running Linux or Mac OS X, the bash shell makes it really easy to perform operations on more than one file at a time. If you are running Windows, we’d recommend installing Cygwin — and during the install process, pick the ImageMagick package. Otherwise you’ll have to download and install that separately. For Linux or Mac, you’ll want to install ImageMagick, which is pretty easy.

First step for the compressing

Now that you have that out of the way, you need to open a terminal window already set to the folder of images you want to manipulate. For cygwin, you’ll probably need to use the cd command and switch to the /cygdrive/c/ folder, like this:

cd /cygdrive/c/

Use the cd and ls commands to figure out where you are, and navigate into the folder that you want to manipulate. If you are a Linux user, you should already know how to do this.

Compress the images file

Now you can finally run the command. Try this one on for size:

for f in *.jpg; do convert -quality 70 $f $f; done

The command uses the for operator to list through the list of files we defined as *.jpg, and then runs the convert command, which is actually ImageMagick, to change the quality of the JPG file down to 70.

If you wanted to compress just a single image, you could do it like this, adjusting the 70 to whatever level of compression you want — 50 would compress a lot more, but you will probably start to notice some serious quality degradation at that point.

convert -quality 70 image.jpg image.jpg

The first time you put the image name is to specify which file to open, and the second time is to specify which file to save it as, which in this example is the same. You could also just change the name of the output file if you wanted to save the existing files, though we’d recommend making a backup of all your images before you do anything.
Newer Post
Previous
This is the last post.

0 comments:

Post a Comment