ROTATE API Endpoint

Version 2.197 (Release Notes ↗)

Description

Rotate an image by a specified number of degrees, with empty spaces filled using the background color. Rotates an image the specified number of degrees. Note that empty spaces left over from rotating the image are filled with the background color.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
img URL Input image URL. For direct uploads, submit a multipart/form-data POST request.
degree Float Rotation angle in degrees (clockwise).
key String Your PixLab API Key ↗. Alternatively, use WWW-Authenticate: header.

Optional

Fields Type Description
blob Boolean Returns image binary if true (default: JSON response).
color String Background color (e.g., "red", "#fffeec"). Default: transparent.

POST Request Body

For direct uploads instead of GET requests:

Allowed Content-Types:

  • multipart/form-data
  • application/json

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

HTTP Response

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

The ROTATE endpoint returns 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 omitted. Otherwise, the raw image binary is returned. The JSON response fields are documented above.

Code Samples


import requests

def rotate_image(image_url: str, degrees: int = 180, api_key: str = 'PIXLAB_API_KEY') -> str:
    """Rotate an image using the PixLab API and return the processed image URL."""
    try:
        response = requests.get(
            'https://api.pixlab.io/rotate',
            params={
                'img': image_url,
                'degree': degrees,
                'key': api_key
            },
            timeout=10
        )
        response.raise_for_status()
        data = response.json()
        
        if data['status'] != 200:
            raise ValueError(data.get('error', 'Unknown error occurred'))
        
        return data['link']
    
    except requests.exceptions.RequestException as e:
        raise ConnectionError(f"API request failed: {e}") from e
    except (KeyError, ValueError) as e:
        raise ValueError(f"Invalid API response: {e}") from e

if __name__ == '__main__':
    try:
        image_url = 'https://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg'
        rotated_url = rotate_image(image_url)
        print(f"Link to the rotated image: {rotated_url}")
    except Exception as e:
        print(f"Error: {e}")
← Return to API Endpoint Listing