Skip to main content

Sirv Image Transformation - Python

A fluent URL builder for Sirv dynamic image transformations. Build transformed image URLs with an intuitive, chainable API — no API credentials required.

Installation

pip install sirv-image

Quick Start

from sirv_image import SirvImage

url = (SirvImage('https://demo.sirv.com/image.jpg')
       .resize(width=300, height=200)
       .format('webp')
       .quality(80)
       .to_url())

# https://demo.sirv.com/image.jpg?w=300&h=200&format=webp&q=80

Constructor

# Full image URL
SirvImage('https://demo.sirv.com/image.jpg')

# Base URL + path
SirvImage('https://demo.sirv.com', '/image.jpg')

API Reference

All methods return self for chaining. Call .to_url() to get the final URL. str(image) also works.

Resize

Method Parameters Description
resize() width=, height=, option= Set dimensions. Option: fit, fill, ignore, noup
width(w) int Set width
height(h) int Set height
scale_by_longest(s) int Resize by longest dimension
thumbnail(size=256) int Create square thumbnail

Crop

Method Parameters Description
crop() width=, height=, x=, y=, type=, pad_width=, pad_height= Crop image. Type: trim, poi, face
clip_path(name) str Apply Photoshop clipping path

Rotation

Method Parameters Description
rotate(degrees) int/float (-180 to 180) Rotate image
flip() — Flip vertically
flop() — Flip horizontally

Format & Quality

Method Parameters Description
format(fmt) str Output format: jpg, png, webp, optimal, original
quality(q) int (0-100) JPEG quality
webp_fallback(fmt) str Fallback for non-WebP browsers
subsampling(value) str Chroma subsampling
png_optimize(enabled=True) bool PNG optimization
gif_lossy(level) int (0-100) GIF lossy compression

Color Adjustments

Method Parameters Description
brightness(v) int (-100 to 100) Adjust brightness
contrast(v) int (-100 to 100) Adjust contrast
exposure(v) int (-100 to 100) Adjust exposure
hue(v) int (-100 to 100) Adjust hue
saturation(v) int (-100 to 100) Adjust saturation
lightness(v) int (-100 to 100) Adjust lightness
shadows(v) int (-100 to 100) Adjust shadows
highlights(v) int (-100 to 100) Adjust highlights
grayscale() — Convert to grayscale
color_level() black=, white= Set color levels
histogram(channel) str Show histogram: r, g, b

Color Effects

Method Parameters Description
colorize() color=, opacity= Apply color overlay
colortone(preset) str Preset: sepia, warm, cold, etc.
colortone() color=, level=, mode= Custom colortone

Effects

Method Parameters Description
blur(v) int (0-100) Apply blur
sharpen(v) int (0-100) Apply sharpening
vignette() value=, color= Apply vignette
opacity(v) int (0-100) Set opacity (PNG)

Text Overlay

.text(content,
      size=,             # Text area width (%)
      font_size=,        # Fixed size (px)
      font_family=,      # Google Fonts name
      font_style=,       # 'normal' | 'italic'
      font_weight=,      # 300-800
      color=,            # Hex or color name
      opacity=,          # 0-100
      outline_width=,    # px
      outline_color=,
      outline_opacity=,
      outline_blur=,
      background_color=,
      background_opacity=,
      align=,            # 'left' | 'center' | 'right'
      position=,         # 'center', 'north', etc.
      position_x=,
      position_y=,
      position_gravity=)

Call .text() multiple times for multiple text layers.

Watermark

.watermark(path,
           position=,         # 'center', 'north', 'tile', etc.
           position_x=,
           position_y=,
           position_gravity=,
           scale_width=,      # px or %
           scale_height=,
           scale_option=,     # 'noup' | 'fit' | 'fill' | 'ignore'
           rotate=,           # -180 to 180
           opacity=,          # 0-100
           layer=,            # 'front' | 'back'
           canvas_color=,
           canvas_opacity=,
           canvas_width=,
           canvas_height=,
           crop_x=, crop_y=,
           crop_width=, crop_height=)

Call .watermark() multiple times for multiple watermarks.

Canvas & Frame

.canvas(width=, height=, color=, position=, opacity=,
        aspect_ratio=, border_width=, border_height=,
        border_color=, border_opacity=)

.frame(style=, color=, width=, rim_color=, rim_width=)

Other

Method Parameters Description
page(num) int PDF page to render
profile(name) str Apply saved profile

Examples

E-commerce Product Image

product = (SirvImage('https://demo.sirv.com/products/shoe.jpg')
           .resize(width=800, height=600, option='fill')
           .format('webp')
           .quality(85)
           .watermark('/brand-logo.png', position='southeast', opacity=30)
           .to_url())

Vintage Photo Effect

vintage = (SirvImage('https://demo.sirv.com/photo.jpg')
           .colortone('sepia')
           .vignette(value=40)
           .frame(style='solid', color='f5e6d3', width=20)
           .to_url())

Testing

pytest

License

MIT

Metadata

Release files for sirv-image 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sirv-image 2.0.0
File Size Uploaded Provenance Actions
sirv_image-2.0.0.tar.gz 10.7 kB Without provenance Details for sirv_image-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sirv-image 2.0.0
File Interpreter ABI Platform Actions
sirv_image-2.0.0-py3-none-any.whl Python 3 none any Details for sirv_image-2.0.0-py3-none-any.whl

Total release size: 19.8 kB

Release files / sirv_image-2.0.0.tar.gz

Download URL sirv_image-2.0.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bc5b7dcfd472e3a96b871ca625ac66751f3267a0a4201c8b5900dfab0bfe86dc
BLAKE2b-256 checksum
How to use checksums
4544441ab90597a2e36bed56d7d7fb81fae50ad3c5aaa4f43a673243fd0f1687
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / sirv_image-2.0.0-py3-none-any.whl

Download URL sirv_image-2.0.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7647fa5e3af7060e0a084a9a8296e83856853f616142f8aaef2a121e5d055823
BLAKE2b-256 checksum
How to use checksums
98f10130ba4fbcaeca643fefccba6e69f5da0d5cae0d12a7d21c61aa3d9b8533
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for sirv-image 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page