🔄

Image Resize

Resize an image by exact dimensions with optional aspect ratio preservation

GET 10 credits /v1/image/resize
curl "https://image.toolkitapi.io/v1/image/resize?url=https://toolkitapi.io/static/samples/sample-image.png&width=800&height=600&maintain_aspect=true&format=jpeg&quality=85"
import httpx

resp = httpx.get(
    "https://image.toolkitapi.io/v1/image/resize?url=https://toolkitapi.io/static/samples/sample-image.png&width=800&height=600&maintain_aspect=true&format=jpeg&quality=85",
)
print(resp.json())
const resp = await fetch("https://image.toolkitapi.io/v1/image/resize?url=https://toolkitapi.io/static/samples/sample-image.png&width=800&height=600&maintain_aspect=true&format=jpeg&quality=85", {
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "image": "/9j/4AAQSkZJRgABAQ...(base64 data)...",
  "format": "jpeg",
  "original_size": {"width": 4032, "height": 3024},
  "new_size": {"width": 800, "height": 600}
}

Try It Live

Live Demo

Description

Resize an image by exact dimensions with optional aspect ratio preservation

How to Use

1

1. Provide the source image via the `url` query parameter.

2

2. Set `width` and/or `height` in pixels. Provide both for exact sizing, or just one for proportional scaling.

3

3. Set `maintain_aspect` to true (default) to prevent distortion when both dimensions are specified.

4

4. Choose the output `format` and `quality` for the resized image.

About This Tool

Use the Image Resize endpoint to change an image's dimensions by specifying target width and/or height. When `maintain_aspect` is true and both dimensions are given, the image is fitted within the bounding box without distortion.

If only width or height is provided, the other dimension is calculated automatically to preserve the aspect ratio. The endpoint uses Lanczos resampling for high-quality downscaling and upscaling.

Why Use This Tool

Frequently Asked Questions

What resampling algorithm is used?
Lanczos resampling (LANCZOS) is used for both upscaling and downscaling. This produces sharp results with minimal aliasing artifacts.
What happens if I provide both dimensions with maintain_aspect=true?
The image is fitted within the bounding box defined by width and height using `thumbnail()`, which scales down to fit without exceeding either dimension. The actual output may be smaller than the specified dimensions.
Can I upscale images?
Yes, but upscaling beyond the original resolution will not add detail. For best quality, avoid upscaling more than 2× the original size.

Start using Image Resize now

Get your free API key and make your first request in under a minute.