Image Optimizer

Parameters

Every transform is a query parameter on the /img/... request. Parameters can be combined freely; unrecognized values return a 400 with a machine-readable error code (see Errors).

ParameterTypeDefaultDescription
f, formatauto | webp | avifautoOutput format.
q, quality1–10085Output quality.
w, width1–10000originalTarget width in px.
h, height1–10000originalTarget height in px.
fitcrop | contain | cover | fill | inside | outside—Resize strategy when both width and height are set.
position, poscenter | top | bottom | left | right | entropy | attentioncenterCrop anchor, used with fit=crop.
blur1–100—Gaussian blur sigma.
rotate, rot0 | 90 | 180 | 2700Rotation in degrees.

Format — f, format

Defaults to auto: the API inspects the request's Accept header and serves the best format the client supports (AVIF, then WebP). Force a specific format by passing webp or avif explicitly.

https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?f=webp
https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?f=avif

Quality — q, quality

An integer from 1 to 100, default 85. Lower values trade visual fidelity for a smaller file.

https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?f=webp&q=90
https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?f=webp&q=30

Resize — w/width, h/height, fit

Set w and/or h to resize. When only one is set, the image scales proportionally. When both are set, fit controls how the source is mapped onto the target box:

  • cover (default when both dimensions are set) — fills the box, cropping if necessary.
  • contain — fits inside the box, letterboxing if necessary.
  • fill — stretches to the exact box, ignoring aspect ratio.
  • crop — fills the box, cropping anchored by position.
  • inside / outside — scales to fit inside or outside the box, preserving aspect ratio.
https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?w=300&h=300&fit=cover
https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?w=300&h=300&fit=contain

Position — position, pos

Sets the crop anchor whenever the resize crops the source — that is,fit=cover, fit=crop (an alias for cover), or the default fit used when both dimensions are set without an explicit fit. Defaults to center. entropy and attention pick the anchor automatically based on image content.

https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?w=300&h=300&fit=crop&position=attention

Blur — blur

A Gaussian blur sigma from 1 to 100.

https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?f=webp&blur=15

Rotate — rotate, rot

One of 0, 90, 180, or 270 degrees.

https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?f=webp&rotate=90

Combining parameters

A typical responsive-image request combines several at once:

https://image-optimizer-two.vercel.app/img/raw.githubusercontent.com/github/explore/main/topics/nodejs/nodejs.png?f=auto&q=70&w=800&fit=cover