SCALE API Endpoint

Version 2.197 (Release Notes ↗)

Description

Scales an image proportionally using a percentage field, ideal for developers and creators looking to resize images efficiently. Scales an image proportionally using a percentage field.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL Input media URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request.
scale Integer Scaling percentage. A value between 1..500. For example, if this field is set to 50, then the image is scaled proportionally to half its size exactly like minify, 100 and the image is scaled proportionally to 2px its size and so forth.
key String Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to.

Optional

Fields Type Description
blob Boolean By default, this API endpoint return a JSON Object holding the link to the image output. But, if this parameter is set to true then the media binary contents is returned instead.

POST Request Body

If you plan to use POST instead of a simple GET request

Allowed Content-Types:

multipart/form-data
application/json

Use multipart/form-data if you want to upload your media file directly (refer to the REST API code samples for a working example). If you are using JSON, then the media file must be already uploaded somewhere. Call store if you want to upload an image for example before invoking this endpoint.

HTTP Response

Fields Type Description
status Integer Status code 200 indicates success, any other code indicates failure.
link URL Link to the image output which is usually stored on the pixlab.xyz storage server unless you set your own S3 keys (refer to your dashboard ↗ on how to do that).
id String Unique media ID.
error String Error message if status != 200.

The API returns application/json if the optional blob parameter is not set.

This endpoint returns a JSON Object after each call only if the optional blob parameter is omitted. Otherwise, the raw image binary is returned. The JSON response contains the following fields:

Code Samples


import requests


def resize_image(image_url: str, api_key: str, scale_percentage: int) -> str:
    """Resize an image using PixLab API and return the processed image URL."""
    params = {
        'img': image_url,
        'key': api_key,
        'scale': scale_percentage
    }
    
    try:
        response = requests.get('https://api.pixlab.io/scale', params=params)
        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"Invalid API response: {e}") from e


if __name__ == '__main__':
    try:
        processed_url = resize_image(
            image_url='http://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
            api_key='My_PIXLAB_API_KEY',
            scale_percentage=50
        )
        print(f"Processed image location: {processed_url}")
    except Exception as e:
        print(f"Error: {e}")
← Return to API Endpoint Listing