DRAWLINES API Endpoint

Version 2.197 (Release Notes ↗)

Description

Draw as many lines as needed on any input image using the DRAWLINES API. Perfect for developers and creators looking to enhance image editing capabilities. Draw as much lines as desired on a given input image.

HTTP Methods

POST

HTTP Parameters

Required

Fields Type Description
img URL Input image URL. If you want to upload your image directly from your app, call store before invoking this one.
lines Array JSON array holding the coordinates of the lines to be drawn (See below).
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.
color String Global color to apply for each line to be drawn which default to white. Use hex color code such as #cef45f if you want to.
strokewidth Float Global line stroke width which default to 2.
strokeopacity Float Global line stroke opacity which default to 0.9.

POST Request Body

Allowed Content-Types:

application/json

Only JSON data is allowed. The field of interest here is the lines parameter which must be a JSON array holding the object coordinates of each line to be drawn on the input image. The following are the required parameters for each object in the line array:

Fields Type Description
startx Integer Starting X coordinate of this line.
starty Integer Starting Y coordinate of this line.
endx Integer Ending X coordinate of this line.
endy Integer Ending Y coordinate of this line.
color String Optional color to apply for this specific line which default to white. Use hex color code such as #cef45f if you want to.

So, a typical line array should look like this (See the example section for a working snippet).


lines = [
     {
       startx: 200,
       starty: 290,
       endx: 452,
       endy: 375
     },
     {
       startx: 85,
       starty: 60,
       endx: 290,
       endy: 175,
       color: 'red'
     }
]

HTTP Response

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 image 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 output image stored on the pixlab.xyz server unless custom S3 keys are configured (see console.pixlab.io for setup).
id String Unique image identifier.
error String Error message if status != 200.

Code Samples


import requests
import json

def draw_lines_on_image(image_url: str, api_key: str, lines: list) -> str:
    """Draw lines on an image using PixLab API.
    
    Args:
        image_url: URL of the image to process
        api_key: PixLab API key
        lines: List of line dictionaries with coordinates and colors
    
    Returns:
        URL of the processed image or error message
    """
    endpoint = 'https://api.pixlab.io/drawlines'
    headers = {'Content-Type': 'application/json'}
    payload = {
        'img': image_url,
        'key': api_key,
        'lines': lines
    }

    try:
        response = requests.post(
            endpoint,
            headers=headers,
            data=json.dumps(payload),
            timeout=10
        )
        response.raise_for_status()
        data = response.json()

        if data.get('status') == 200:
            return data.get('link', '')
        return data.get('error', 'Unknown error occurred')

    except requests.exceptions.RequestException as e:
        return f"Request failed: {str(e)}"

if __name__ == '__main__':
    image_url = 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg'
    api_key = 'PIXLAB_API_KEY'
    lines = [
        {
            "startx": 200,
            "starty": 290,
            "endx": 452,
            "endy": 375,
            "color": "white"
        },
        {
            "startx": 85,
            "starty": 60,
            "endx": 290,
            "endy": 175,
            "color": "red"
        }
    ]

    result = draw_lines_on_image(image_url, api_key, lines)
    if result.startswith('http'):
        print(f"Pic location: {result}")
    else:
        print(f"Error: {result}")
← Return to API Endpoint Listing