Skip to content

Transform

GET /v1/transform

The transform API takes a source GIF, JPEG, or PNG image and returns it transformed as per the given parameters.

Query Parameter Reference

ParameterDefaultDescription
key Required The API key.
src Required The URL of the source image. Must be in GIF, JPEG, or PNG format.
fmtjpegThe desired format of the output. One of gif, jpeg, or png.
hThe target height. Must be a positive integer below 5000.
wThe target width. Must be a positive integer below 5000.

Example

Include this in a HTML document to add a random cat photo resized to 300 pixels wide and with a relative height:

<img
  src="https://optimedia.loughran.dev/v1/transform?key=1234abcd&src=/cat&w=300"
  alt="kitty cat"
/>

Integrate with a CDN

The transform API is immutable and designed to be used with a CDN to cache transformations for fast access. The same combination of input parameters will always result in the same output, meaning the result is safe to cache indefinitely.

Why use a CDN?

Pairing Optimedia with a CDN results in several benefits:

  • Faster response times for your users. Transformation outputs can be cached and distributed globally, meaning subsequent requests by users will load quickly no matter where they are.

  • Less API calls. The API only needs to be called once per combination of input parameters, conserving API calls.

  • More economical. Transformations are computed lazily, and do not need to be recomputed, saving energy.