Python Examples¶
The Image Toolkit Python SDK covers image processing, generation, metadata extraction, favicon discovery, and Liquid-template rendering.
Install¶
pip install toolkitapi
Basic setup¶
from toolkitapi import Image
image = Image(api_key="tk_...")
Quick examples¶
Resize an image¶
with Image(api_key="tk_...") as image:
result = image.resize(
url="https://toolkitapi.io/photo.jpg",
width=800,
maintain_aspect=True,
format="webp",
)
print(result["new_size"])
Convert between formats¶
with Image(api_key="tk_...") as image:
result = image.convert(
"png",
"webp",
url="https://toolkitapi.io/logo.png",
quality=85,
)
print(result["content_type"])
Generate a QR code¶
with Image(api_key="tk_...") as image:
result = image.qr("https://toolkitapi.io", format="png")
print(result["format"])
Extract colors¶
with Image(api_key="tk_...") as image:
colors = image.extract_colors(url="https://toolkitapi.io/photo.jpg", count=5)
print(colors)
Render a Liquid template as an image¶
with Image(api_key="tk_...") as image:
card = image.from_template(
template="<html><body><h1>{{ title }}</h1></body></html>",
variables={"title": "Launch day"},
width=1200,
height=630,
)
print(card["width"], card["height"])