WEBFIT API Endpoint

Version 2.197 (Release Notes ↗)

Description

Generate a 320x240px thumbnail optimized for use in web sites. This API endpoint is a just wrapper around thumbnail with width & height set respectively to 320 and 240.

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, submit a multipart/form-data POST request.
key String Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter.

Optional

Fields Type Description
blob Boolean By default, returns a JSON Object with the output image link. If set to true, returns the raw media binary instead.

POST Request Body

Use this if submitting a POST request instead of GET.

Allowed Content-Types:

multipart/form-data
application/json

Use multipart/form-data for direct file uploads (see REST API code samples or The PixLab Github Repository↗ for examples). For JSON, the file must already be hosted elsewhere. Call store to upload an image before invoking this endpoint.

HTTP Response

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

This endpoint returns a JSON response unless the blob parameter is specified, in which case it returns the raw image binary. The response object contains the following fields:
Fields Type Description
status Integer Status code 200 indicates success, any other code indicates failure.
link URL Link to the processed image stored on the pixlab.xyz CDN unless custom S3 keys are configured (see your console for configuration).
id String Unique media identifier.
error String Error description when status ≠ 200.

Code Samples


import requests


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

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

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


if __name__ == '__main__':
    fetch_image_processing_result(
        image_url='http://www.drodd.com/images15/nature31.jpg',
        api_key='My_PIXLAB_API_KEY'
    )
← Return to API Endpoint Listing