Python Image Compressor

A simple image compressor written in Python 2.7. This program will take all .png files in the current directory and compress them into 128 by 128 .png images. If the original image is not of a square proportion, the longest dimension will be compressed down to 128 px. The shorter proportion will be compressed down proportionally. The program uses anti-aliase algorithm. It takes an input of “keyword” and produces output with file name “keyword””original file name”.png. For example, if original file name is “img1.png”. With a keyword of “new”, the resulting thumbnail will be saved under file name “newimg1.png”

For now, the only way to change compression dimensions is to change the code. I wrote this program for my own use so I didn’t bother with too much user interface.

You must first augment the Python compiler with PIL before running this program.

Here’s instruction on how to install Pip:

Here’s instruction on how to install Pillow, a fork on PIL:

from PIL import Image
import glob, os
from sys import argv

print "Please enter output keyword: "
keyword = raw_input (prompt)

size = 128, 128

for infile in glob.glob("*.png"):
    file, ext = os.path.splitext(infile)
    im =
    im.thumbnail(size, Image.ANTIALIAS) + file+ "_thumbnail.png", "PNG")
    i += 1
    print "done with "+file+"\n"