API Endpoint Access URL
https://api.pixlab.io/encrypt
Get Your API Key & Try ENCRYPT Now ↗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}")
fetch('https://api.pixlab.io/encrypt?img=https://pixlab.io/images/bencrypt.png&pwd=superpass&key=PIXLAB_API_KEY')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Link to the encrypted picture: " + reply.link);
//use https://api.pixlab.io/decrypt with your passphrase to make it readable again
}
})
.catch(error => console.error('Error:', error));
<?php
$params = [
'img' => 'https://pixlab.io/images/bencrypt.png',
'pwd' => 'superpass',
'key' => 'PIXLAB_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/encrypt?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new RuntimeException('cURL error: ' . curl_error($ch));
}
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
echo "Link to the encrypted picture: " . $reply['link'];
// use https://api.pixlab.io/decrypt with your passphrase to make it readable again
}
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://api.pixlab.io/encrypt')
params = { 'img' => 'https://pixlab.io/images/bencrypt.png', 'pwd' => 'superpass', 'key' => 'PIXLAB_API_KEY' }
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
puts "Link to the encrypted picture: #{reply['link']}"
#use https://api.pixlab.io/decrypt with your passphrase to make it readable again
end