CHOP API Endpoint

Version 2.197 (Release Notes ↗)

Description

CHOP API endpoint removes a selected region from an image and collapses the remaining parts to fill the removed area. Removes a region of an image and collapses the image to occupy the removed portion.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL Input image URL. If uploading directly from your app, submit a multipart/form-data POST request.
width Integer Width of the chopped area.
height Integer Height of the chopped area.
x Integer X coordinates of the chopped area.
y Integer Y coordinates of the chopped area.
key String Your PixLab API Key ↗. Alternatively, embed your key in the WWW-Authenticate: HTTP header to omit this parameter.

Tip: If either height or width is missing (but not both), the available length is applied to the missing dimension.

Optional

Fields Type Description
blob Boolean Returns JSON with output image link by default. Set to true to receive binary image data instead.

POST Request Body

Use when submitting POST requests instead of GET.

Allowed Content-Type:

  • multipart/form-data
  • application/json

Use multipart/form-data for direct image uploads (see REST API code samples). For JSON, ensure your image is already hosted. Call store to upload images 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 image 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 unless the blob parameter is specified, in which case the image binary data is returned directly. The JSON response structure is documented above.

Code Samples


import requests


def fetch_image_link():
    try:
        response = requests.get(
            'https://api.pixlab.io/chop',
            params={
                'img': 'http://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
                'height': 20,
                'x': 45,
                'y': 72,
                'key': 'PIXLAB_API_KEY'
            },
            timeout=10
        )
        response.raise_for_status()
        data = response.json()
        
        if data.get('status') == 200:
            return data.get('link')
        else:
            print(f"Error: {data.get('error', 'Unknown error')}")
            return None
            
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
        return None


if __name__ == '__main__':
    image_link = fetch_image_link()
    if image_link:
        print(f"Link to the pic: {image_link}")
← Return to API Endpoint Listing