NEWIMAGE API Endpoint

Version 2.197 (Release Notes ↗)

Description

Create and customize new images with specific width, height, and background color using the NEWIMAGE API endpoint. Perfect for developers and creators looking to generate dynamic visuals, including mimicking Facebook-style messages. Dynamically create a new image with a desired width, height and background color. You can invoke for example the drawtext endpoint after the freshly created image is returned to mimic facebook visual messages (See python example below).

HTTP Methods

GET

HTTP Parameters

Fields Type Description
width Integer Desired image width. If omitted, the height parameter is used as the width value.
height Integer Desired image height. If omitted, the width parameter is used as the height value.
key String Your PixLab API Key ↗. Alternatively, you can pass it via the WWW-Authenticate: HTTP header and omit this parameter.

Optional

Fields Type Description
blob Boolean Returns raw image binary data when set to true. Default behavior returns a JSON Object with the output URL.
color String Background color (e.g., white, green). Defaults to gray. Use tr for transparency or hex codes like #cef48e.
export Format Output format (default: PNG). Supported: JPEG, BMP, etc.

HTTP Response

The response content type is 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 image binary contents are returned directly. The following fields are included in the JSON response body:

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 media ID.
error String Error message if status != 200.

Code Samples


import requests
import sys

def create_image(width: int, height: int, color: str, api_key: str) -> str:
    """Create a new image with specified dimensions and background color."""
    response = requests.get(
        'https://api.pixlab.io/newimage',
        params={
            'key': api_key,
            'width': width,
            'height': height,
            'color': color
        }
    )
    response.raise_for_status()
    data = response.json()
    if data['status'] != 200:
        raise ValueError(data.get('error', 'Unknown error creating image'))
    return data['link']

def draw_text(image_url: str, text: str, api_key: str, **kwargs) -> str:
    """Draw text on an existing image."""
    params = {
        'img': image_url,
        'key': api_key,
        'text': text,
        **kwargs
    }
    response = requests.get('https://api.pixlab.io/drawtext', params=params)
    response.raise_for_status()
    data = response.json()
    if data['status'] != 200:
        raise ValueError(data.get('error', 'Unknown error drawing text'))
    return data['link']

def main():
    API_KEY = 'My_PIXLAB_API_KEY'
    try:
        image_url = create_image(300, 300, 'yellow', API_KEY)
        result_url = draw_text(
            image_url,
            'bonjour',
            API_KEY,
            cap=True,
            color='black',
            font='wolf',
            center=True
        )
        print(f"Pic location: {result_url}")
    except (requests.RequestException, ValueError) as e:
        print(f"Error: {e}", file=sys.stderr)
        sys.exit(1)

if __name__ == '__main__':
    main()
← Return to API Endpoint Listing