Created
March 17, 2016 10:23
-
-
Save cmg-dev/87ac3b3732d63d642e7f to your computer and use it in GitHub Desktop.
This little script will help us to get the images straight for our website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import os, sys | |
from PIL import Image | |
size = (768,512) | |
def compress(files, | |
output_format="JPEG", | |
jpg_quality=100, | |
out_file_name_postfix=".small"): | |
"""Compress a list of images to smaller versions. | |
""" | |
for infile in files: | |
f, e = os.path.splitext(infile) | |
outfile = f + out_file_name_postfix + ".jpg" | |
print("processing '{}' to '{}'".format(infile, outfile)) | |
if infile != outfile: | |
try: | |
im = Image.open(infile) | |
im.thumbnail(size) | |
im.save(outfile, output_format, quality=jpg_quality) | |
except IOError: | |
print("unable to convert '{}'".format(infile)) | |
if __name__ == "__main__": | |
compress(sys.argv[1:]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment