Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Using Smush.it or Firebug's built-in image optimizer I realize we can reduce the file size of all of our web jpgs. By quite much actually. As we have hundreds of thousands of images, is there any way to batch optimize (and replace) these images using any tool you know of (except the aforementioned as they only operate one by one)? Really don't want to do this manually one by one. :(

share|improve this question
    
I think you want lossy compression, not lossless compression. –  David Schwartz Aug 22 '12 at 14:34
    
No, I want loss-less... lossy compression destroys visual image quality and that's a big no-no. –  user1603240 Aug 23 '12 at 19:43
    
Firebug's "optimization" was a lossy compression process. For most images it simply reduced the image quality by a small enough amount that people wouldn't notice but the file size shrinks drastically. This is a very noticeable difference in JPEG images with quality levels over 90%. –  Chris S Nov 25 at 0:52

2 Answers 2

I would recommend the ImageMagick utilities from http://www.imagemagick.org/script/index.php

You can use the convert utility from ImageMagick along with some simple command-line scripting. You can use a Unix system or Cygwin in Windows

The exact convert command would be convert -quality 50 in.jpg out.jpg. Adjust the quality parameter to the desired value. (Note: This is a lossy operation)

The convert utility can also convert to other formats, like PNG, which is lossless.

If you have Unix or bash on Cygwin, the full operation would be:

for file in *.jpg; do
    filebase=`basename $file`
    convert $file -quality 50 ${filebase}.new.jpg
done

Another alternative is to use Gimp in batch mode:

http://www.gimp.org/tutorials/Basic_Batch/

share|improve this answer
    
Yes, I do need loss-less. Very nice - thx for the Gimp link. –  user1603240 Aug 23 '12 at 7:02

The tool you want is called jpegtran. It's available in most Linux distributions and a Windows binary is also available. The command you want to use is:

jpegtran -copy none -progressive -outfile out_filename.jpg in_filename.jpg

You should easily be able to script this with a batch file or shell script to run on all your image files. Note that this may remove copyright notices and the like. If that's an issue, change -copy none to
-copy comments.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.