Last active
May 27, 2016 13:06
-
-
Save bolismauro/6a7bea3c2b3e2b78948382351ece9362 to your computer and use it in GitHub Desktop.
Generate pandified versions of an image
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
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