SMARTCROP API Endpoint

Version 2.197 (Release Notes ↗)

Description

Deprecated API endpoint. Use crop instead

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.
width Integer Desired crop Width. If this field is missing, then the height field is applied for this one.
height Integer Desired crop Height. If this field is missing, then the width field is applied for this one.
x Integer The X coordinate of the cropped region's top left corner.
y Integer The Y coordinate of the cropped region's top left corner.
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 image binary contents is returned instead.

POST Request Body

This section details the requirements for using a POST request 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

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

This endpoint returns a JSON Object after each call unless the blob parameter is specified, in which case the raw media binary is returned. The JSON response contains the following fields:

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

Code Samples


import requests


def extract_face(image_url: str, x: int, y: int, width: int, height: int, api_key: str) -> str:
    """Extract a face from an image using specified coordinates.
    
    Args:
        image_url: URL of the source image
        x: X coordinate of the top-left corner
        y: Y coordinate of the top-left corner
        width: Width of the rectangle
        height: Height of the rectangle
        api_key: PixLab API key
        
    Returns:
        URL of the cropped image or error message
    """
    try:
        response = requests.get(
            'https://api.pixlab.io/crop',
            params={
                'img': image_url,
                'key': api_key,
                'x': x,
                'y': y,
                'width': width,
                'height': height
            },
            timeout=10
        )
        response.raise_for_status()
        data = response.json()
        
        if data['status'] != 200:
            return f"Error: {data.get('error', 'Unknown error')}"
            
        return f"Face location: {data['link']}"
        
    except requests.exceptions.RequestException as e:
        return f"Request failed: {str(e)}"
    except (KeyError, ValueError) as e:
        return f"Invalid response: {str(e)}"


if __name__ == "__main__":
    result = extract_face(
        image_url='http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
        x=164,
        y=95,
        width=145,
        height=145,
        api_key='PIXLAB_API_KEY'
    )
    print(result)
← Return to API Endpoint Listing