Resize images
Serve smaller copies of an image, in the best format each browser takes, from one uploaded file.
Upload an image once, and ask for it at the size you need with a preset. We make the smaller copy the first time it is asked for, keep it, and serve it from then on.
Ask for a preset
Add ?preset= to a file’s public address:
GET https://files.digitospace.com/k3m9q2x7v1c8r4t6w0z5/products/shoe.jpg?preset=thumbEvery bucket has four presets:
| Preset | Size | Fit |
|---|---|---|
thumb | 200 × 200 | cover: fills the square and crops the rest |
small | 480 wide | scale-down: never larger than the original |
medium | 960 wide | scale-down |
large | 1,600 wide | scale-down |
<img
src="https://files.digitospace.com/k3m9q2x7v1c8r4t6w0z5/products/shoe.jpg?preset=medium"
alt="A red shoe"
/>For a private file, name the preset when you ask for the download link:
-d '{"key": "photos/receipt.jpg", "preset": "medium"}'The format is chosen for you
We send AVIF to browsers that take it, when the preset is at most 1,200 pixels wide, then WebP, then JPEG, or PNG for PNG and GIF originals. The answer says which with Content-Type. Keep one address in your page and each browser gets the smallest file it can show.
Add your own presets
A bucket can hold 20 presets of its own:
curl -X PUT "$STORAGE_URL/buckets/products/presets/card" \
-H "Authorization: Bearer $STORAGE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"width": 640, "height": 360, "fit": "cover", "quality": 75}'Changing a preset makes new copies the next time each image is asked for. See the Buckets reference for every field.
What can be resized
- JPEG, PNG, WebP, GIF (its first frame), and HEIC photos from phones.
- Originals up to 15 MB and 50 megapixels.
- Anything else answers
415. SVG and other files are served as they are without a preset.
If an image cannot be resized, we send the original rather than an error, so your page still shows it.
How many you can make
Each project can make 200 new resized images a month. A copy already made keeps being served and does not count again, and the count starts again on the first day of each month, in UTC. Past the allowance, a size not made yet gets the original image until the next month.
When a file changes
Replacing a file makes new copies from the new file. Taking a file down, deleting it, or making its bucket private stops its copies too, within a minute.
Last updated