amuck-landowner

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

MannDude

Just a dude
vpsBoard Founder
Moderator
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

Article Submitter
Verified Provider
How about:

Create temporary image > delete previous image > move temporary image
 

rds100

New Member
Verified Provider
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

New Member
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

Well-Known Member
Verified Provider
Not sure for Linux but I use FastStone Photo Resizer for bulk image manipulation (renames, converting, resizing, etc...).
 

Kakashi

Active Member
Verified Provider
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

Not to be taken seriously, ever!
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

New Member
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

New Member
You can do it with python and PIL


Code:
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()
 

MannDude

Just a dude
vpsBoard Founder
Moderator
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

Article Submitter
Verified Provider
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

Just a dude
vpsBoard Founder
Moderator
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 :)
 
Top
amuck-landowner