Skip to content

Instantly share code, notes, and snippets.

@ariesduanmu
Created November 29, 2019 08:12
Show Gist options
  • Select an option

  • Save ariesduanmu/42500f4180454f6c9f4ab71fa2ebebc8 to your computer and use it in GitHub Desktop.

Select an option

Save ariesduanmu/42500f4180454f6c9f4ab71fa2ebebc8 to your computer and use it in GitHub Desktop.
compress image using tinypng(https://tinypng.com/)
import os
import tinify
from PIL import Image
tinify.key = "THIS IS MY KEY"
orginal_path = r"ORIGINAL_DIR"
compressed_path = r"COMPRESSED_DIR"
for image_name in os.listdir(orginal_path):
image_path = os.path.join(orginal_path, image_name)
tiny_image_path = os.path.join(compressed_path, image_name)
tinify.from_file(image_path).to_file(tiny_image_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment