← Back to blog

Small Pics URL API: A Practical Guide

· Small Pics

The Small Pics URL API lets you resize, crop, format, and optimize images by adding query parameters to any image URL. No SDK required, no build step, no config file. You construct a URL, and Small Pics returns an optimized image.

This post walks through the API from the basics to more advanced features.

How does the Small Pics URL API work?

Every Small Pics URL follows the same pattern:

https://your-domain.smallpics.io/image.jpg?w=800&h=600&fit=cover&fm=webp

The path is your origin image. The query parameters are your transforms. Small Pics processes the image on the first request, caches it at the edge, and serves it from cache on subsequent requests.

How do you resize an image? (w and h)

The most common operation. Set the width, height, or both.

<!-- Width only (height scales proportionally) -->
<img src="https://your-domain.smallpics.io/photo.jpg?w=800" />

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

For retina displays, use dpr to multiply the dimensions automatically:

<!-- Renders at 1600x1200 for 2x screens -->
<img src="https://your-domain.smallpics.io/photo.jpg?w=800&h=600&dpr=2" />

dpr accepts values from 1 to 8.

What fit modes does Small Pics support? (fit)

When you specify both w and h, fit controls how the image fills those dimensions.

ValueBehavior
containFits inside the box, preserving aspect ratio (default)
maxLike contain, but never upscales
coverFills the box, cropping the overflow
cropSame as cover
fillStretches to fit, may upscale
fill-maxLike fill, but never upscales
stretchIgnores aspect ratio, stretches to exact dimensions

You can also use crop-x%-y% to control the crop focal point:

<!-- Crop with focus on the top-right -->
<img src="https://your-domain.smallpics.io/photo.jpg?w=800&h=600&fit=crop-100%-0%" />

How do you change the output format? (fm)

Small Pics supports AVIF, WebP, JPEG, Progressive JPEG, PNG, GIF, and JPEG XL.

<img src="https://your-domain.smallpics.io/photo.jpg?w=800&fm=avif" />
ValueFormat
avifAVIF (default)
webpWebP
jpgJPEG
pjpgProgressive JPEG
pngPNG
gifGIF
jxlJPEG XL

How do you control compression quality? (q)

Controls compression quality on a 0-100 scale. Default is 90.

<!-- Lower quality, smaller file -->
<img src="https://your-domain.smallpics.io/photo.jpg?w=800&fm=webp&q=75" />

For most photos, 70-80 is a good balance between quality and file size. Go lower for thumbnails, higher for hero images.

How do you crop a specific region? (crop)

For precise control, use crop to extract a region before resizing. The format is width,height,x,y:

<!-- Extract a 500x500 region starting at coordinates 100,200 -->
<img src="https://your-domain.smallpics.io/photo.jpg?crop=500,500,100,200&w=400" />

This crops first, then applies any w/h resize.

How do you rotate and flip images? (or and flip)

Rotate in 90-degree increments, or set auto to respect EXIF orientation (the default):

<img src="https://your-domain.smallpics.io/photo.jpg?w=800&or=90" />

Flip horizontally, vertically, or both:

<img src="https://your-domain.smallpics.io/photo.jpg?w=800&flip=h" />

What image adjustments are available? (bri, con, gam, sharp)

Fine-tune the output with brightness, contrast, gamma, and sharpness.

<!-- Slightly brighter and sharper -->
<img src="https://your-domain.smallpics.io/photo.jpg?w=800&bri=10&sharp=30" />
ParameterRangeDefault
bri-100 to 1000
con-100 to 1000
gam0.1 to 9.99-
sharp0 to 100-

How do you set a background color? (bg)

When using contain or fill fit modes, the background is visible. Set it with bg:

<!-- White background behind a contained image -->
<img src="https://your-domain.smallpics.io/logo.png?w=400&h=400&fit=contain&bg=white" />

<!-- Hex color -->
<img src="https://your-domain.smallpics.io/logo.png?w=400&h=400&fit=contain&bg=ff6600" />

Supports CSS color names and hex values (3, 4, 6, or 8 digits).

How do you add borders? (border)

Add a border around the image. The format is width,color,method:

<!-- 10px red border -->
<img src="https://your-domain.smallpics.io/photo.jpg?w=800&border=10,red,overlay" />

The method can be overlay (draws on top of the image), shrink (shrinks the image to make room), or expand (increases the canvas).

How do you add watermarks?

Overlay a watermark from your configured watermarks directory:

<img
	src="https://your-domain.smallpics.io/photo.jpg?w=1200&mark=logo.png&markpos=bottom-right&markalpha=50"
/>
ParameterDescription
markWatermark filename
markposPosition (e.g. center, top-left, bottom-right)
markalphaOpacity, 0-100
markw / markhWatermark dimensions
markpadPadding around the watermark
markx / markyOffset from edges
markfitHow the watermark scales
markoriginImage origin for the watermark

How do you enable progressive loading? (interlace)

Enable progressive encoding for JPEG and PNG:

<img src="https://your-domain.smallpics.io/photo.jpg?w=1200&fm=jpg&interlace=1" />

This makes images render progressively in the browser, appearing blurry first and sharpening as data loads. Useful for large above-the-fold images.

How do you secure image URLs? (s)

If you have URL signing enabled on your image source, append the signature:

<img src="https://your-domain.smallpics.io/photo.jpg?w=800&s=abc123..." />

Signed URLs prevent anyone from modifying your transform parameters. See our docs for details on generating signatures.

How do you combine multiple transforms?

Here’s a real-world example for a responsive hero image:

<picture>
	<source
		srcset="https://your-domain.smallpics.io/hero.jpg?w=1200&h=630&fit=cover&fm=avif&q=80"
		type="image/avif"
	/>
	<source
		srcset="https://your-domain.smallpics.io/hero.jpg?w=1200&h=630&fit=cover&fm=webp&q=80"
		type="image/webp"
	/>
	<img
		src="https://your-domain.smallpics.io/hero.jpg?w=1200&h=630&fit=cover&fm=jpg&q=80"
		alt="Hero image"
		width="1200"
		height="630"
		loading="eager"
	/>
</picture>

And a responsive srcset for different screen widths:

<img
	srcset="
		https://your-domain.smallpics.io/photo.jpg?w=400&fm=webp   400w,
		https://your-domain.smallpics.io/photo.jpg?w=800&fm=webp   800w,
		https://your-domain.smallpics.io/photo.jpg?w=1200&fm=webp 1200w
	"
	sizes="(max-width: 600px) 400px, (max-width: 1000px) 800px, 1200px"
	src="https://your-domain.smallpics.io/photo.jpg?w=800&fm=webp"
	alt="Responsive image"
	loading="lazy"
/>

That covers everything the URL API can do. If you want the full parameter reference, it’s all in the docs. And if you want to try it on your own images, you can start a free trial, no credit card needed.

Frequently asked questions

How does the Small Pics URL API work?
You construct a URL with your origin image path and add query parameters for transforms. Small Pics processes the image on the first request, caches it at the edge, and serves it from cache on subsequent requests. No SDK required.
How do you resize an image with Small Pics?
Use the w and h query parameters. For example, ?w=800 resizes to 800px wide with proportional height. Use both ?w=800&h=600 for exact dimensions. Add dpr=2 for retina displays.
What fit modes does Small Pics support?
Small Pics supports contain (default), max, cover, crop, fill, fill-max, and stretch. You can also use percentage-based crop positioning like fit=crop-75%-25% for focal point control.
How do you serve AVIF and WebP with Small Pics?
Use the fm parameter. For example, ?fm=avif or ?fm=webp. Small Pics defaults to AVIF. Supported formats are AVIF, WebP, JPEG, Progressive JPEG, PNG, GIF, and JPEG XL.
What quality setting should I use for web images?
For most photos, a quality of 70-80 (via the q parameter) balances file size and visual quality well. Use lower values for thumbnails, higher for hero images. The default is 90.
Does Small Pics support signed URLs?
Yes. If URL signing is enabled on your image source, append the signature with the s parameter. Signed URLs prevent unauthorized modification of transform parameters.

More from the blog

View all posts

Ready to make your website's images smaller?

Plans from $9/mo. Start a 14-day free trial, no credit card required.