Skip to main content

Image Transformation

img-src provides powerful on-demand image transformation through URL parameters. Images are transformed at the edge and cached for optimal performance.

Basic URL Structure

https://img-src.io/i/{username}/{path}?{parameters}
Or using the secondary CDN domain:
https://cdn.img-src.io/{username}/{path}?{parameters}

Transformation Parameters

Quick Reference

Size & Layout

ParameterDescriptionValuesExample
wWidth in pixels1-10000?w=800
hHeight in pixels1-10000?h=600
fitFit modecover, contain, fill, scale-down?fit=cover
aspectAspect ratiooriginal, 1:1, 4:3, 16:9, 3:2, 21:9?aspect=16:9

Quality & Display

ParameterDescriptionValuesExample
qQuality (compression)1-100 (default: 80)?q=85
dprDevice pixel ratio (Retina)1, 1.5, 2, 3?dpr=2
cropCrop positioncenter, top, bottom, left, right, attention, entropy?crop=attention
grayscaleConvert to grayscaletrue, false?grayscale=true

Effects & Transform

ParameterDescriptionValuesExample
blurGaussian blur0-100?blur=10
sharpenSharpen intensity0-100?sharpen=15
rotateRotation angle0, 90, 180, 270, auto?rotate=90
flipFlip/mirrorh, v, both?flip=h

Presets (Pro)

ParameterDescriptionValuesExample
p:nameApply presetPreset name?p:thumbnail

Width & Height

Resize images by specifying width (w) and/or height (h) in pixels:
<!-- Width only (height auto-calculated) -->
<img src="https://img-src.io/i/john/photo.jpg?w=800" />

<!-- Height only (width auto-calculated) -->
<img src="https://img-src.io/i/john/photo.jpg?h=600" />

<!-- Both dimensions -->
<img src="https://img-src.io/i/john/photo.jpg?w=800&h=600" />

Fit Mode

Control how the image fits within the specified dimensions:
ModeDescription
coverFill dimensions, cropping if needed (default)
containFit within dimensions, preserving aspect ratio
fillStretch to fill dimensions exactly
scale-downLike contain, but never upscale
<!-- Cover: fills 200x200, crops excess -->
<img src="https://img-src.io/i/john/photo.jpg?w=200&h=200&fit=cover" />

<!-- Contain: fits within 200x200, may have letterboxing -->
<img src="https://img-src.io/i/john/photo.jpg?w=200&h=200&fit=contain" />

<!-- Scale-down: never enlarges small images -->
<img src="https://img-src.io/i/john/photo.jpg?w=2000&fit=scale-down" />
Original (4:3)covercontainfill
400x300Cropped to 200x200200x150Stretched to 200x200

Quality

Adjust compression quality (1-100, default: 80):
<!-- High quality for hero images -->
<img src="https://img-src.io/i/john/hero.jpg?w=1920&q=90" />

<!-- Lower quality for thumbnails -->
<img src="https://img-src.io/i/john/thumb.jpg?w=100&q=60" />
Quality 80-85 provides a good balance between file size and visual quality for most use cases.

Output Format

The output format is determined by the file extension in the URL. You can serve the original format without conversion, or convert to a different format.
FormatExtensionBest For
Original(same as uploaded)No conversion, fastest delivery
WebP.webpGeneral use, best compression
AVIF.avifMaximum compression
JPEG.jpg, .jpegUniversal compatibility
PNG.pngTransparency, lossless
<!-- Serve original format (uploaded as photo.jpg) -->
<img src="https://img-src.io/i/john/photo.jpg?w=800" />

<!-- Convert to WebP -->
<img src="https://img-src.io/i/john/photo.webp?w=800" />

<!-- Convert to AVIF for maximum compression -->
<img src="https://img-src.io/i/john/photo.avif?w=800" />
AVIF Limitations:
  • Maximum resolution: 8 megapixels (~3500×2300)
  • Maximum dimension: 4000px on either side
  • Larger images are automatically scaled down before AVIF encoding

Aspect Ratio

Constrain the output to a specific aspect ratio:
<!-- Square crop -->
<img src="https://img-src.io/i/john/photo.jpg?w=400&aspect=1:1&fit=cover" />

<!-- Widescreen -->
<img src="https://img-src.io/i/john/photo.jpg?w=1200&aspect=16:9&fit=cover" />
Available values: original, 1:1, 4:3, 16:9, 3:2, 21:9

DPR (Device Pixel Ratio)

Serve higher resolution images for Retina displays:
<!-- 2x for Retina displays (outputs 800px image for 400px display size) -->
<img src="https://img-src.io/i/john/photo.jpg?w=400&dpr=2" />
Available values: 1, 1.5, 2, 3

Crop Position

Control where the crop occurs when using fit=cover:
<!-- Focus on faces/objects automatically -->
<img src="https://img-src.io/i/john/portrait.jpg?w=200&h=200&fit=cover&crop=attention" />

<!-- Crop from the top -->
<img src="https://img-src.io/i/john/photo.jpg?w=800&h=400&fit=cover&crop=top" />
ValueDescription
centerCenter of the image (default)
top, bottom, left, rightEdge positions
top-left, top-right, bottom-left, bottom-rightCorner positions
attentionAuto-detect important area (faces, objects)
entropyArea with highest visual complexity

Grayscale

Convert images to black and white:
<img src="https://img-src.io/i/john/photo.jpg?w=800&grayscale=true" />

Blur

Apply Gaussian blur (0-100):
<!-- Light blur for background -->
<img src="https://img-src.io/i/john/bg.jpg?w=1920&blur=10" />

<!-- Heavy blur for privacy -->
<img src="https://img-src.io/i/john/photo.jpg?w=800&blur=50" />

Sharpen

Increase image sharpness (0-100):
<!-- Subtle sharpening for product images -->
<img src="https://img-src.io/i/john/product.jpg?w=800&sharpen=15" />
Use sharpen values between 10-30 for subtle enhancement. Higher values may introduce artifacts.

Rotate

Rotate the image:
<!-- Rotate 90 degrees clockwise -->
<img src="https://img-src.io/i/john/photo.jpg?rotate=90" />

<!-- Auto-rotate based on EXIF data -->
<img src="https://img-src.io/i/john/photo.jpg?rotate=auto" />
Available values: 0, 90, 180, 270, auto

Flip

Mirror the image horizontally or vertically:
<!-- Horizontal flip (mirror) -->
<img src="https://img-src.io/i/john/photo.jpg?flip=h" />

<!-- Vertical flip -->
<img src="https://img-src.io/i/john/photo.jpg?flip=v" />

<!-- Both -->
<img src="https://img-src.io/i/john/photo.jpg?flip=both" />

Combining Parameters

Chain multiple parameters with &:
<img src="https://img-src.io/i/john/photo.jpg?w=800&h=600&fit=cover&q=85" />
To convert format, change the file extension:
<img src="https://img-src.io/i/john/photo.webp?w=800&h=600&fit=cover&q=85" />

Using Presets (Pro)

Pro users can save transformation configurations as presets:
<!-- Apply a preset -->
<img src="https://img-src.io/i/john/photo.jpg?p:thumbnail" />

<!-- Preset with override -->
<img src="https://img-src.io/i/john/photo.jpg?p:thumbnail&q=90" />
See Presets Guide for setup instructions.

Responsive Images

Use srcset for responsive images:
<img
  src="https://img-src.io/i/john/photo.jpg?w=400"
  srcset="
    https://img-src.io/i/john/photo.jpg?w=400 400w,
    https://img-src.io/i/john/photo.jpg?w=800 800w,
    https://img-src.io/i/john/photo.jpg?w=1200 1200w
  "
  sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px"
  alt="Responsive image"
/>

Supported Input Formats

img-src accepts these input formats:
  • Common: JPEG, PNG, WebP, GIF
  • Professional: TIFF, BMP, ICO, SVG
  • Modern: HEIC/HEIF, AVIF
  • Specialized: TGA, PNM, QOI, HDR, EXR

Caching

Transformed images are cached at the edge:
  • First request: Image is fetched, transformed, and cached
  • Subsequent requests: Served directly from cache
  • Cache duration: 30 days (configurable)
Cache is automatically invalidated when:
  • The original image is updated
  • The image is deleted
  • You call the purge API endpoint

Cache Headers

Responses include standard cache headers:
Cache-Control: public, max-age=2592000
ETag: "abc123..."
Use If-None-Match header with the ETag for conditional requests.

Best Practices

  • Hero/banner images: 85-90
  • Product images: 80-85
  • Thumbnails: 60-75
  • Backgrounds: 70-80
Use the file extension in your URL to specify the output format (e.g., .webp, .avif). img-src will convert your image to that format automatically.
Prevents small images from being upscaled and looking blurry.
Pro users should create presets for frequently used transformations to simplify URLs and ensure consistency.