API: Tinify (TinyPNG)

Optimise your images to be more lightweight with TinyPNG.

19 Sep 2022

Works with Alfred Alfred

API key

tiny-png-pricing.jpg

No password required for signup! API key obtained in <1mns! 😁

API Dashboard

API Documentation

pip3 install --upgrade tinify

Authentication

import tinify
tinify.key = "YOUR_API_KEY"

Compressing

locally:

source = tinify.from_file("unoptimized.webp")
source.to_file("optimized.webp")

url:

source = tinify.from_url("https://tinypng/images/panda-happy.png")
source.to_file("optimized.png")

Resizing

Resizing counts as one additional compression. For example, if you upload a single image and retrieve the optimized version plus 2 resized versions this will count as 3 compressions in total.

source = tinify.from_file("large.jpg")
resized = source.resize(
    method="fit",
    width=150,
    height=100
)
resized.to_file("thumbnail.jpg")

Compression count

compressions_this_month = tinifypression_count

links

social