CONVERT API Endpoint

Version 2.197 (Release Notes ↗)

Description

Convert static images to different formats like JPEG to PNG or BMP to TIFF while maintaining original dimensions. Use additional endpoints for resizing, cropping, thumbnails, and avatars. For GIF conversions, use the makegif endpoint. Convert a static image to another format such as JPEG to PNG, BMP to TIFF, etc. The output image will keep its original dimension. Call resize, crop, thumbnail, avatar, etc. if you want to adjust the width & height of the output image. For GIF conversion, please rely on makegif instead.

HTTP Methods

GET, POST

HTTP Parameters

Fields Type Description
img URL Input image URL. If uploading directly from your app, submit a multipart/form-data POST request.
export String Output image format (JPEG, TIFF, BMP, PNG, etc.)
key String Your PixLab API Key ↗. Can also be embedded in WWW-Authenticate: header.

Optional

Fields Type Description
blob Boolean Returns image binary contents when true (default: JSON with output URL)
background String Background color (hex code like #cef45f). Use tr or transparent for transparency.
compression Integer JPEG quality (0-100). JPEG conversion only.

POST Request Body

Allowed Content-Types:

multipart/form-data
application/json

Use multipart/form-data for direct image uploads (see samples). For JSON, the image must be pre-uploaded (use store endpoint first).

HTTP Response

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

This API endpoint returns a JSON Object after each call only if the optional blob parameter is not set. Otherwise, the image binary contents are returned instead. The following are the JSON fields returned in the response body:

Fields Type Description
status Integer Status code 200 indicates success, any other code indicates failure.
link URL Link to the media 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
from typing import Dict, Any

def convert_image_to_png(image_url: str, api_key: str) -> None:
    """Convert JPEG image to PNG with transparent background using PixLab API.
    
    Args:
        image_url: URL of the JPEG image to convert.
        api_key: Your PixLab API key.
    """
    try:
        response = requests.get(
            'https://api.pixlab.io/convert',
            params={
                'img': image_url,
                'export': 'png',
                'background': 'transparent',
                'key': api_key
            },
            timeout=10
        )
        response.raise_for_status()
        data: Dict[str, Any] = response.json()
        
        if data.get('status') == 200:
            print(f"PNG Image Link: {data['link']}")
        else:
            print(f"Error: {data.get('error', 'Unknown error occurred')}")
            
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
    except ValueError as e:
        print(f"Invalid JSON response: {e}")

# Example usage:
# convert_image_to_png(
#     image_url='https://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
#     api_key='PIXLAB_API_KEY'
# )
← Return to API Endpoint Listing