professional image resizing

Image Resizer
API Documentation

Resize images with multiple modes (fit, fill, stretch, crop), custom dimensions, or predefined size presets โ€” with configurable quality and output formats over a simple REST API. Built for developers.

Try it now Back to API Hub

Overview

The Image Resizer API provides advanced image resizing with multiple resize modes including fit, fill, stretch, and crop. It supports custom dimensions, 40+ predefined size presets, and maintains high image quality with configurable compression settings and output formats. Perfect for responsive web design, thumbnail generation, and content optimization.

Base URL & Authentication

Base URL

Base URL

https://api.chemhub.com/api/v1

Authentication

Include your API credentials in every request header.

Headers

X-API-Key: your_api_key
X-API-Secret: your_secret
Content-Type: application/json

Get API Keys

Follow these steps to obtain your API credentials:

1

Log In to Your Account

Existing Users: Go to /login to access your dashboard

New Users: Visit /register to create your free account first

2

Access Your Profile

Once you log in, click on your profile picture in the top-right corner, then click on "Your profile" from the dropdown menu.

3

Create API Key

From your profile page, proceed to the "API Keys" section and create a key by filling in a name you prefer.

Example name

"Image resizer bot" or "My Thumbnail Service"

4

Save Your Credentials

Click on "Create API Key" to generate your credentials, then immediately copy and save both the API Key and Secret.

Critical Warning

Your secret key will only be displayed once! Copy it immediately and store it securely. You won't be able to see it again.

Security Notice

Never share your API keys publicly or commit them to version control. Treat them like passwords โ€” regenerate immediately if compromised.

Rate Limits

Free tier: 150 requests/day | Pro tier: 1000 requests/day. Check your dashboard for current usage and limits.

Endpoints

๐Ÿ’š Health CheckGET /img_resizer/health
๐Ÿ–ผ๏ธ Resize ImagePOST /img_resizer/resize
๐Ÿ“Š Get Image InfoPOST /img_resizer/info

Health Check

GET/img_resizer/health

Health check endpoint to verify the Image Resizer service status and available backends.

Response

Success Response

{
  "success": true,
  "status": "healthy",
  "img_resizer_backends": ["pil", "opencv"],
  "supported_formats": [".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff"],
  "max_file_size_mb": 10,
  "standard_sizes": ["thumbnail", "small", "medium", "large", "hd", "full_hd", "4k", "avatar_xl"],
  "timestamp": "2026-07-23T12:00:00"
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/img_resizer/health"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

res = requests.get(url, headers=headers)
print(res.json())

cURL

curl -X GET https://api.chemhub.com/api/v1/img_resizer/health \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret"

JavaScript

fetch('https://api.chemhub.com/api/v1/img_resizer/health', {
  method: 'GET',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  }
})
.then(res => res.json())
.then(console.log);

Resize Image

POST/img_resizer/resize

Resize an image to custom dimensions or a predefined size preset. Upload the file as multipart/form-data.

Form Parameters

FieldTypeDefaultDescription
fileFileโ€”Image file (required) โ€” PNG, JPEG, WebP, BMP, or TIFF
widthintโ€”Target width in pixels (required if size_preset not used)
heightintโ€”Target height in pixels (required if size_preset not used)
size_presetstringโ€”Predefined size (optional) โ€” thumbnail, small, medium, hd, full_hd, avatar_xl, etc.
resize_modestringfitResize mode โ€” fit, fill, stretch, crop
qualityint85Output quality 1-100 (JPEG/WebP)
maintain_aspectbooltrueWhether to maintain aspect ratio
output_formatstringpngOutput format โ€” png, jpg, jpeg, webp

Resize Modes

Response

On success the endpoint returns the resized image bytes directly with Content-Type: image/png|image/jpeg|image/webp.

cURL Example

cURL

curl -X POST "https://api.chemhub.com/api/v1/img_resizer/resize" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret" \
  -F "file=@image.jpg" \
  -F "width=1024" \
  -F "height=768" \
  -F "resize_mode=fit" \
  -F "quality=90" \
  -F "output_format=jpeg" \
  --output resized_image.jpg

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/img_resizer/resize"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

with open("image.jpg", "rb") as f:
    files = {"file": f}
    data = {
        "width": 1024,
        "height": 768,
        "resize_mode": "fit",
        "quality": 90,
        "output_format": "jpeg"
    }
    response = requests.post(url, headers=headers, files=files, data=data)

if response.status_code == 200:
    with open("resized_image.jpg", "wb") as out:
        out.write(response.content)
    print("Image resized successfully!")
else:
    print(response.json())

JavaScript

const form = new FormData();
form.append('file', fileInput.files[0]);
form.append('width', '1024');
form.append('height', '768');
form.append('resize_mode', 'fit');
form.append('quality', '90');
form.append('output_format', 'jpeg');

fetch('https://api.chemhub.com/api/v1/img_resizer/resize', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  },
  body: form
})
.then(async res => {
  if (res.ok) {
    const blob = await res.blob();
    const url = URL.createObjectURL(blob);
    console.log('Resized image URL:', url);
  } else {
    console.log(await res.json());
  }
});

Get Image Info

POST/img_resizer/info

Get information about an uploaded image without resizing. Upload the file as multipart/form-data.

Form Parameters

Response

Success Response

{
  "success": true,
  "info": {
    "width": 1920,
    "height": 1080,
    "format": "JPEG",
    "mode": "RGB",
    "file_size_bytes": 245760,
    "aspect_ratio": 1.7778
  },
  "standard_sizes": {
    "thumbnail": [150, 150],
    "small": [300, 300],
    "medium": [600, 600]
  }
}

cURL Example

cURL

curl -X POST "https://api.chemhub.com/api/v1/img_resizer/info" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret" \
  -F "file=@image.jpg"

Size Presets

Predefined sizes for common use cases. Pass the preset name as the size_preset form parameter.

CategoryPresets (width x height)
Thumbnails / Genericthumbnail 150x150, small 300x300, medium 600x600, large 1200x1200, xlarge 1920x1920, xxlarge 2560x2560
HD / Videohd 1280x720, full_hd 1920x1080, 4k 3840x2160
Squares / Gridssquare_small 200x200, square_medium 400x400, square_large 800x800, social_square 1080x1080, social_post_square 1200x1200
Portrait / Storiessocial_story 1080x1920, portrait_small 720x1280, portrait_medium 1080x1920, portrait_large 1440x2560
Landscape / Link Previewsocial_link_preview 1200x628, landscape_small 800x450, landscape_medium 1280x720, landscape_large 1920x1080
Banners / Herobanner_small 468x60, banner_medium 728x90, banner_large 970x250, hero_standard 1600x500, hero_large 1920x600
Avatarsavatar_xs 32x32, avatar_small 64x64, avatar_medium 128x128, avatar_large 256x256, avatar_xl 512x512
Mobilemobile_small 360x640, mobile_medium 480x800, mobile_large 720x1280
Retina (2x)thumbnail_2x 300x300, small_2x 600x600, medium_2x 1200x1200, large_2x 2400x2400, hd_2x 2560x1440, full_hd_2x 3840x2160

Python SDK

Complete Python SDK with custom resize, preset resize, and image info endpoints.

Complete SDK Class

import requests
import os
from pathlib import Path

BASE_URL = "https://api.chemhub.com/api/v1"
API_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"

headers = {
    "X-API-Key": API_KEY,
    "X-API-Secret": API_SECRET
}

# --- Health Check ---
def check_health():
    return requests.get(f"{BASE_URL}/img_resizer/health", headers=headers).json()

# --- Resize to custom dimensions ---
def resize_image(image_path, width=800, height=600, resize_mode="fit", quality=85, output_format="jpeg"):
    with open(image_path, "rb") as image_file:
        files = {"file": image_file}
        data = {
            "width": width,
            "height": height,
            "resize_mode": resize_mode,
            "quality": quality,
            "output_format": output_format
        }
        response = requests.post(
            f"{BASE_URL}/img_resizer/resize",
            headers=headers,
            files=files,
            data=data
        )

    if response.status_code == 200:
        output_path = str(Path(image_path).with_suffix("")) + f"_resized_{width}x{height}.{output_format}"
        with open(output_path, "wb") as f:
            f.write(response.content)
        print(f"Image resized! Saved to: {output_path}")
        return output_path
    else:
        print(f"Error: {response.status_code} - {response.text}")
        return None

# --- Resize using a size preset ---
def resize_with_preset(image_path, size_preset="medium", resize_mode="fit", quality=85, output_format="jpeg"):
    with open(image_path, "rb") as image_file:
        files = {"file": image_file}
        data = {
            "size_preset": size_preset,
            "resize_mode": resize_mode,
            "quality": quality,
            "output_format": output_format
        }
        response = requests.post(
            f"{BASE_URL}/img_resizer/resize",
            headers=headers,
            files=files,
            data=data
        )

    if response.status_code == 200:
        output_path = str(Path(image_path).with_suffix("")) + f"_resized_{size_preset}.{output_format}"
        with open(output_path, "wb") as f:
            f.write(response.content)
        print(f"Image resized! Saved to: {output_path}")
        return output_path
    else:
        print(f"Error: {response.status_code} - {response.text}")
        return None

# --- Get image info ---
def get_image_info(image_path):
    with open(image_path, "rb") as image_file:
        files = {"file": image_file}
        response = requests.post(
            f"{BASE_URL}/img_resizer/info",
            headers=headers,
            files=files
        )
    return response.json()

# --- Test all endpoints ---
if __name__ == "__main__":
    image_path = "image1.jpeg"

    print("=== IMAGE RESIZER API TEST ===")

    health = check_health()
    print(f"Health: {health.get('status', 'unknown')}")

    info = get_image_info(image_path)
    print(f"Info: {info.get('info', {})}")

    print("\n1. Resizing image to 800x600 (fit mode):")
    resize_image(image_path, width=800, height=600, resize_mode="fit", quality=85, output_format="jpeg")

    print("\n2. Resizing image using 'thumbnail' preset:")
    resize_with_preset(image_path, size_preset="thumbnail", resize_mode="fit", quality=95, output_format="jpeg")

Errors & Status Codes

Error Response Format

Error Response

{
  "success": false,
  "error": "Invalid dimensions",
  "message": "Target size must be between 16x16 and 5000x5000"
}

Status Codes

CodeMeaning
200Success
400Bad request / invalid parameters / unsupported file format
401Invalid or missing API key/secret
413File too large (max 10MB)
422Invalid dimensions or parameters
429Rate limit exceeded
500Internal server error / processing failed

Limitations

Maximum file size: 10MB
Maximum dimensions: 5000 x 5000 pixels (min 16 x 16)
Rate limit: 15 requests per minute
Supported formats: PNG, JPEG, WebP, BMP, TIFF
Processing time: Up to 15 seconds for large images