RESIZE API Endpoint

Version 2.197 (Release Notes ↗)

Description

Resize API endpoint scales images to desired dimensions. For proportional and intelligent scaling, consider using the smartresize endpoint.

Scales an image to the desired dimensions. Consider using smartresize for proportional & intelligent scaling of your images.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL Input media URL. If uploading directly from your app, submit a multipart/form-data POST request.
width Integer Desired new width. If omitted, the height value will be applied.
height Integer Desired new height. If omitted, the width value will be applied.
key String Your PixLab API Key ↗. Can also be passed via WWW-Authenticate: header.

Optional

Fields Type Description
blob Boolean Returns image binary data when true (default: JSON with output URL).

POST Request Body

Use when submitting POST requests instead of GET:

Allowed Content-Types:

  • multipart/form-data
  • application/json

Use multipart/form-data for direct file uploads (see examples). For JSON, media must be pre-uploaded - use store endpoint first if needed.

HTTP Response

Fields Type Description
status Integer Status code 200 indicates success, any other code indicates failure.
link URL Link to the media output stored on pixlab.xyz storage server unless custom S3 keys are configured (see console for setup).
id String Unique media identifier.
error String Error message when status != 200.

The API returns application/json when the optional blob parameter is omitted. If blob is enabled, the endpoint returns raw binary data instead. Successful JSON responses contain these fields:

Required

No required parameters for this endpoint.

Optional

All parameters are optional for this endpoint.

Code Samples


import requests

def resize_image(image_url: str, width: int, height: int, api_key: str) -> str:
    """Resize an image using PixLab API and return the processed image URL."""
    try:
        response = requests.get(
            'https://api.pixlab.io/resize',
            params={
                'img': image_url,
                'key': api_key,
                'width': width,
                'height': height
            },
            timeout=10
        )
        response.raise_for_status()
        data = response.json()
        
        if data['status'] != 200:
            raise ValueError(data.get('error', 'Unknown error occurred'))
            
        return data['link']
    
    except requests.exceptions.RequestException as e:
        raise ConnectionError(f"API request failed: {e}") from e
    except (KeyError, ValueError) as e:
        raise ValueError(f"API response error: {e}") from e

# Example usage
if __name__ == "__main__":
    try:
        resized_url = resize_image(
            image_url='http://www.drodd.com/images15/nature31.jpg',
            width=640,
            height=400,
            api_key='My_PIXLAB_API_KEY'
        )
        print(f"Resized image location: {resized_url}")
    except Exception as e:
        print(f"Error: {e}")
← Return to API Endpoint Listing