Image Optimizer

Image Optimizer API

Web Development

Reduce image file sizes instantly to improve website speed and lower hosting costs. Compress JPEG, PNG, WebP, GIF and BMP images and save them as JPEG, PNG, WebP or AVIF.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

20 requests per minute

Endpoints

1 endpoint available

Overview

Re-encode an image as JPEG, PNG, WebP or AVIF at a quality you choose, and optionally fit it inside a width and height. Send the image as multipart form data in the file field. The response body is the new image file.

Notes

  • Accepted input: JPEG, PNG, WebP, GIF, AVIF, TIFF and SVG, up to 20 MB and 50 megapixels. BMP, ICO and HEIC files return 415. Animated GIFs use the first frame.
  • The EXIF orientation is applied to the pixels, and all metadata (EXIF, GPS, ICC) is removed.
  • width and height are a box to fit inside, keeping the aspect ratio. Send one or both. The image can be enlarged to fit. The output can be at most 10000 pixels per side.
  • For PNG, quality below 100 makes sharp reduce the image to a smaller colour palette.

Endpoints

POST
https://opentools.ca/api/v1/tools/image-optimizer
Compress an image and return the new file

Request Body

Content-Type: multipart/form-data

ParameterTypeRequiredDescription
file
file
Required
The image, up to 20 MB and 50 megapixels. JPEG, PNG, WebP, GIF (first frame), AVIF, TIFF or SVG.
format
string
Enum: jpeg, png, webp, avif
OptionalOutput format.Default: jpeg
quality
number
OptionalQuality from 1 to 100.Default: 80
width
number
OptionalMaximum width in pixels, 1 to 10000. The aspect ratio is kept.
height
number
OptionalMaximum height in pixels, 1 to 10000. The aspect ratio is kept.

Response Example

HTTP/1.1 200 OK
Content-Type: image/webp
Content-Disposition: attachment; filename="photo-optimized.webp"

<binary file data>

Error Codes

400
Bad Request - Missing file, invalid option, or output over 10000 pixels per side
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key is inactive or expired, or the request IP is not allowed
413
Payload Too Large - File over 20 MB or image over 50 megapixels
415
Unsupported Media Type - Not an image the server can read (BMP, ICO and HEIC are not supported)
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

curl -X POST https://opentools.ca/api/v1/tools/image-optimizer \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@photo.jpg" \
  -F "format=webp" \
  -F "quality=75" \
  -F "width=1600" \
  -o photo-optimized.webp

Ready to get started?

Create an API key to start using the Image Optimizer API.

Rather use it in your browser? Open the Image Optimizer