Last active
May 11, 2016 07:21
-
-
Save border/7a17342a5b05fd251aa7 to your computer and use it in GitHub Desktop.
Revisions
-
border revised this gist
Aug 29, 2015 . No changes.There are no files selected for viewing
-
border revised this gist
Aug 29, 2015 . No changes.There are no files selected for viewing
-
border created this gist
Aug 29, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import sys import os import getopt import tinify tinify.key = 'YOUR_API_KEY' def usage(): print "python " + sys.argv[0] + " -i inputfile" def tinypng(source): filepath = os.path.dirname(source) filename = os.path.basename(source) target = filepath + os.sep + "tiny-" + filename print target tinify.from_file(source).to_file(target) def scandir(startdir): os.chdir(startdir) for obj in os.listdir(os.curdir): if os.path.isdir(obj): scandir(obj) os.chdir(os.pardir) else: filename = os.getcwd() + os.sep + obj fname=os.path.splitext(filename) if fname[1].lower() == ".png": tinypng(filename) opts, args = getopt.getopt(sys.argv[1:], "(hH)i:", ["help", "input="]) input_file = '' for op, value in opts: if op == "-i": input_file = value elif op == "-h": usage() sys.exit() if len(sys.argv) != 3: usage() sys.exit() if os.path.isdir(input_file): scandir(input_file) else: tinypng(input_file)