BORDER API Endpoint

Version 2.197 (Release Notes ↗)

Description

Create custom borders for images with desired colors using the BORDER API endpoint. Ideal for developers and creators looking to enhance image aesthetics. Generate a border with a desired color for a given image.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL Input image URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request.
width Integer The width of the border (Max value is set to 300).
height Integer The height of the border (Max value is set to 300).
color String A string representing the color for example: red, blue, yellow, etc or a color code like #fffeec, #e45cff, etc. If this field is missing, then the default color is set to gray.
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.

Tip: If one of the height or width parameter is missing (but not both), then the available length is applied to the missing side.

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

To facilitate direct image uploads, utilize multipart/form-data. Please consult the REST API code samples for a functional implementation. If you are using JSON, then your image must be already uploaded somewhere. Call store if you want to upload an image before invoking this endpoint.

HTTP Response

The BORDER 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 it returns the raw image binary. The response JSON 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 pixlab.xyz storage unless custom S3 keys are configured (see console.pixlab.io for configuration).
id String Unique image identifier.
error String Error description when status ≠ 200.

Code Samples


import requests

API_URL = 'https://api.pixlab.io/border'
API_KEY = 'PIXLAB_API_KEY'

params = {
    'img': 'http://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
    'width': 20,
    'color': 'yellow',
    'key': API_KEY
}

try:
    response = requests.get(API_URL, params=params, timeout=10)
    response.raise_for_status()
    data = response.json()
    
    if data.get('status') == 200:
        print(f"Link to the pic: {data['link']}")
    else:
        print(data.get('error', 'Unknown error occurred'))
        
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")
except ValueError:
    print("Invalid JSON response")
except KeyError:
    print("Missing expected data in response")
← Return to API Endpoint Listing