Last active
June 16, 2018 04:10
-
-
Save jerivas/3085ba151c3e2f8e663d to your computer and use it in GitHub Desktop.
TinyPNG API via Python. Optimizes .png and .jpg files in the current directory and outputs to "optimized/".
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 characters
from __future__ import print_function | |
import os | |
import tinify | |
tinify.key = "" # Fill your developer key here | |
exts = ("jpg", "png", "jpeg") | |
basewidth = 1500 | |
files = [f for f in os.listdir(".") if os.path.isfile(f) and f.endswith(exts)] | |
for f in files: | |
print("Optimizing %s" % f) | |
source = tinify.from_file(f) | |
resized = source.resize(method="scale", width=basewidth) | |
resized.to_file("optimized/%s" % f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment