Skip to content

Instantly share code, notes, and snippets.

@bolismauro
Last active May 27, 2016 13:06
Show Gist options
  • Save bolismauro/6a7bea3c2b3e2b78948382351ece9362 to your computer and use it in GitHub Desktop.
Save bolismauro/6a7bea3c2b3e2b78948382351ece9362 to your computer and use it in GitHub Desktop.
Generate pandified versions of an image
import glob
import os
import tinify
SOURCE_FOLDER = 'images'
DEST_FOLDER = 'dest'
tinify.key = "jbRr5F8gUwTwAehGm_4RDK_bvYdGSLnw"
images = glob.glob("./{}/**/*.png".format(SOURCE_FOLDER))
for src in images:
dest = src.replace(SOURCE_FOLDER, DEST_FOLDER)
dest_folder = os.path.dirname(dest)
if not os.path.exists(dest_folder):
os.makedirs(dest_folder)
if os.path.exists(dest):
continue
print "Generating {} -> {}".format(src, dest)
source = tinify.from_file(src)
source.to_file(dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment