CROPGIF API Endpoint

Version 2.197 (Release Notes ↗)

Description

Extracts a region from each frame of a GIF file. Use the crop endpoint for other media formats. Available in the Prod Plan and up.

Extracts a region from each frame of a given GIF file. Use crop for other media format. This endpoint is available starting from the Prod Plan and up.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL Input GIF URL. If you want to upload your gif directly from your app, call store before invoking this endpoint.
width Integer Desired crop Width. If omitted, the height value is applied.
height Integer Desired crop Height. If omitted, the width value is applied.
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 ↗. Alternatively, embed your key in the WWW-Authenticate: HTTP header to omit this parameter.

Optional

Fields Type Description
blob Boolean Returns JSON with output GIF link by default. Set to true to return raw GIF binary data instead.

POST Request Body

Use when sending POST requests instead of GET.

Allowed Content-Types:

multipart/form-data
application/json

Use multipart/form-data for direct file uploads (see REST API code samples). For JSON, media must be pre-uploaded. Call store to upload files 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 gif 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 not set. Otherwise, the GIF binary content is returned directly.

Code Samples


import requests


def crop_gif(image_url: str, api_key: str, x: int, y: int, width: int) -> None:
    try:
        response = requests.get(
            'https://api.pixlab.io/cropgif',
            params={
                'img': image_url,
                'key': api_key,
                'x': x,
                'y': y,
                'width': width
            },
            timeout=10
        )
        response.raise_for_status()
        data = response.json()

        if data['status'] != 200:
            print(f"Error: {data.get('error', 'Unknown error')}")
        else:
            print(f"GIF location: {data['link']}")

    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
    except (KeyError, ValueError) as e:
        print(f"Invalid response format: {e}")


if __name__ == "__main__":
    crop_gif(
        image_url='http://cloud.addictivetips.com/wp-content/uploads/2009/testing.gif',
        api_key='PIXLAB_API_KEY',
        x=150,
        y=70,
        width=256
    )
← Return to API Endpoint Listing