# Converting entire directory of JPG files to progressive JPGs and reduce quality/size?



## MannDude (Mar 29, 2014)

I'm interested in bulk converting an entire directory of JPG files into progressive JPGs while also stripping quality to about 85% of the original in an effort to reduce file sizes. These are for the vpsBoard avatars, and I believe it can be done with _jpegtran_ however I am uncertain how to proceed with doing it in bulk while also retaining the original file names. Most tutorials I've stumbled upon would have the files rewritten from, for example, oldfile.jpg to newfile.jpg . I'd like to maintain the file names in the process.

Any ideas?


----------



## Nett (Mar 29, 2014)

How about:

Create temporary image > delete previous image > move temporary image


----------



## rds100 (Mar 29, 2014)

I don't know what parameters jpegtran expects, but assuming it's simething like "jpegtran -options oldfile newfile", you could do something like this:

cd olddir

for i in *.jpg ; do jpegtran -options $i newdir/$i ; done


----------



## manacit (Mar 29, 2014)

You could do this pretty easily with the scripting language of your choice. I'd do it in python - get a list of the files and for each one rename it to $name_old, resize that one and save it as the original name. That gives you a directory with the originals as well as the resized new ones.


----------



## KuJoe (Mar 29, 2014)

Not sure for Linux but I use FastStone Photo Resizer for bulk image manipulation (renames, converting, resizing, etc...).


----------



## Kakashi (Mar 29, 2014)

I've used Adobe Fireworks for this. You create an export template stating what quality,size,colour etc... you want the image at. Then go to Batch processing, select all the files and select the template to apply to the batch. Works wonders.


----------



## mikho (Mar 29, 2014)

I would copy the images to a sub folder and then convert from that sub folder to the original folder.


That way you still have the original image if something goes fubar.


The script would be pretty easy to create in the language you prefer.


----------



## yomero (Mar 29, 2014)

With imagemagick (take a backup first):

find . -name '*.jpg' -exec convert -strip -interlace Plane -quality 85 {} {} \;

Take all the jpg files in the current directory (recursive) and apply the conversion. The -strip parameter is optional, it will remove the metadata and color profiles of the pictures to reduce the size even more.


----------



## 5n1p (Mar 29, 2014)

You can do it with python and PIL



```
import os
from PIL import Image


img_dir = '/path/to/images'




def reduce_quality():
    img_files = [f for f in os.listdir(img_dir) if f.endswith('JPG')]
    for i in range(len(img_files)):
        img_file = Image.open(img_dir+"/"+img_files[i])
        img_file_opt = img_file.resize((120, 120), Image.ANTIALIAS)
        img_file_opt.save(img_dir+"/"+img_files[i], optimize=True, quality=85)


reduce_quality()
```


----------



## Mun (Mar 29, 2014)

http://cdn.content-network.net/api/shrink/shrink_new.php?img=http://www.zreoarchive.org/lib/cover_old.jpg&w=&h=&shrink=100

Could also use the above, no guarantees on the success of really large images or how progressive it is, though it is coded to do so.

Mun


----------



## Mun (Mar 29, 2014)

http://cdn.content-network.net/api/shrink/shrink_new.php?img=http://haysvillelibrary.files.wordpress.com/2010/06/large-magellanic-cloud-complete-with-annotations-eso.jpg&w=&h=&shrink=100

better example that you can see the interlacing.

Mun


----------



## hellogoodbye (Mar 29, 2014)

I use FastStone Photo Resizer as well, it's freeware and it also allows you to retain the same filenames.


----------



## ConnerCG (Mar 30, 2014)

It's always a RIOT then I do image manipluation --

http://luci.criosweb.ro/riot/

I have more flexibility with RIOT, with choosing compression algorithms and targeted file sizes.

Either this or FastStone Photo Resizer would server you well.


----------



## MannDude (Mar 31, 2014)

Thanks fellas, I'll look into these more!

The entire directory of uploaded avatars will be converted. I ran a test locally on a couple individual avatars converting them in GIMP and reducing quality to 80%. Turned a 100X100, 21KB avatar .JPG to about 11.2KB. So it's certainly worth doing. I couldn't tell a difference in quality visually... and as they're avatars they don't need to be crystal clear even if quality is reduced slightly. Too small to note. Every little bit helps. 

The real trouble will come when, down the road, I want to convert the rest of the avatars that were uploaded since my last conversion. But I'll figure that out when the time comes.


----------



## Nett (Mar 31, 2014)

MannDude said:


> The real trouble will come when, down the road, I want to convert the rest of the avatars that were uploaded since my last conversion. But I'll figure that out when the time comes.


You should be able to filter by the date/time of the last edit.


----------



## MannDude (Mar 31, 2014)

Nett said:


> You should be able to filter by the date/time of the last edit.


With any amount of luck I'll write a bash script that just runs nightly or weekly to update the newer, unconverted files. We'll see


----------



## Nett (Mar 31, 2014)

"Cron image compressor" haha.


----------

