ENCRYPT API Endpoint

Version 2.197 (Release Notes ↗)

Description

Converts plain image pixels to enciphered pixels, making the image unreadable until decrypted using the decrypt endpoint. Ideal for secure image transmission. Converts plain pixels of a given image to enciphered pixels. The image is not readable until it has been deciphered via decrypt.

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. PixLab recommend the PNG format but you are free to use any format suitable for you task.
pwd String Passphrase. The image is not readable until it has been deciphered using decrypt with this passphrase.
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.

POST Request Body

If you plan to use POST instead of a simple GET request

Allowed Content-Types:

multipart/form-data
application/json

Use multipart/form-data if you want to upload your image directly. If you are using JSON, then your image must be already uploaded somewhere. Call store if you want to upload an image for example before invoking this endpoint.

HTTP Response

The ENCRYPT endpoint returns data in application/json format 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 processed image stored on pixlab.xyz unless custom S3 keys are configured (see your dashboard ↗ for setup).
id String Unique identifier for the processed image.
error String Error message when status ≠ 200.

Code Samples


import requests


def encrypt_image(image_url: str, password: str, api_key: str) -> str:
    """Encrypt an image using PixLab API and return the encrypted image URL."""
    try:
        response = requests.get(
            'https://api.pixlab.io/encrypt',
            params={
                'img': image_url,
                'pwd': password,
                '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:
        encrypted_url = encrypt_image(
            image_url='https://pixlab.io/images/bencrypt.png',
            password='superpass',
            api_key='PIXLAB_API_KEY'
        )
        print(f"Link to the encrypted picture: {encrypted_url}")
        # Use https://api.pixlab.io/decrypt with your passphrase to decrypt
    except Exception as e:
        print(f"Error: {e}")
← Return to API Endpoint Listing