fit

The fit transformation scales an image to fit within specified dimensions while maintaining aspect ratio, then adds padding around it to reach the exact target size. Perfect for creating uniform canvas sizes without cropping, ideal for product galleries, card layouts, or uniform displays.

Serving Content via CDN

The Media API is a CDN-based service that serves transformed images via GET requests. When you request a transformed image URL, the transformation is applied dynamically on the first request and then cached for subsequent requests.

URL Pattern

https://media.vyso.io/fit:width=W:height=H:background=COLOR/ASSET_ID.jpg

Examples

Fit to 800x600 (No Crop)

curl -i GET https://media.vyso.io/fit:width=800:height=600/ASSET_ID.jpg

Fit with White Padding

curl -i GET https://media.vyso.io/fit:width=600:height=600:background=ffffff/ASSET_ID.jpg

Fit Square with Padding

curl -i GET https://media.vyso.io/fit:width=400:height=400:background=000000/ASSET_ID.jpg

Fit Large Canvas (Centered)

curl -i GET https://media.vyso.io/fit:width=1000:height=800:background=rgb(200,200,200)/ASSET_ID.jpg

Fit to 500x500 with Blue Background

curl -i GET https://media.vyso.io/fit:width=500:height=500:background=4a90e2/ASSET_ID.jpg

On the first request, you'll receive a X-Cache: MISS header while the transformation is applied and cached. Subsequent requests will return X-Cache: HIT.

Parameters

widthREQUIRED

Target canvas width in pixels. Positive integer (e.g., 800).

heightREQUIRED

Target canvas height in pixels. Positive integer (e.g., 600).

backgroundOPTIONAL

Padding background color. Accepted formats:

  • Hex color (without #): ffffff (white)
  • RGB: rgb(255,255,255)
  • CSS color name: white
  • Default: ffffff (white)

Response

The API returns an image scaled to fit within the canvas dimensions with padding added to reach the exact target size. The image maintains its aspect ratio and is centered on the background. The response format depends on the format of the asset stored in the Vyso asset cloud.

Content-Type: Determined by the stored asset format (e.g., image/jpeg, image/png)