API Endpoint Access URL
https://api.pixlab.io/pixelgenerate
Get Your API Key & Try PIXELGENERATE Now ↗Description
Generate random pixel images for machine learning training with the PIXELGENERATE API endpoint. Ideal for creating background samples. Generates a set of random pixels. This endpoint is similar to newimage except that the image contents is filled with random pixels. This is very useful for generating background (negative) samples for feeding Machine Learning training algorithms.
HTTP Methods
GET
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
width |
Integer | Desired image width. If omitted, the height parameter value will be used. |
height |
Integer | Desired image height. If omitted, the width parameter value will be used. |
key |
String | Your PixLab API Key ↗. Alternatively, you can pass it in the WWW-Authenticate: HTTP header and omit this parameter. |
Optional
Fields | Type | Description |
---|---|---|
blob |
Boolean | When true, returns the raw image binary instead of a JSON response containing the image URL. |
color |
String | Background color (e.g. white , green ). Defaults to transparent. Use tr for transparency or hex codes like #cef48e . |
export |
Format | Output format (default: PNG). Supported: JPEG , BMP , etc. |
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 media ID. |
error |
String | Error message if status != 200. |
The 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 not set. Otherwise the image binary contents is returned directly.
Code Samples
import requests
import sys
def generate_random_image(api_key: str, width: int = 300, height: int = 300) -> str:
"""Generate a random pixel image using the PixLab API.
Args:
api_key: Your PixLab API key.
width: Width of the generated image in pixels.
height: Height of the generated image in pixels.
Returns:
URL of the generated image.
Raises:
SystemExit: If the API request fails.
"""
try:
response = requests.get(
'https://api.pixlab.io/pixelgenerate',
params={
'key': api_key,
'width': width,
'height': height
},
timeout=10
)
response.raise_for_status()
data = response.json()
if data['status'] != 200:
print(f"Error: {data.get('error', 'Unknown error')}", file=sys.stderr)
sys.exit(1)
return data['ssl_link']
except requests.exceptions.RequestException as e:
print(f"API request failed: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
API_KEY = "PIXLAB_API_KEY" # Replace with your actual API key
image_url = generate_random_image(API_KEY)
print(f"Randomly generated image location: {image_url}")
fetch('https://api.pixlab.io/pixelgenerate?key=PIXLAB_API_KEY&width=300&height=300')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.error(reply.error);
return;
}
console.log("Randomly generated image location: " + reply.ssl_link);
})
.catch(error => console.error('Error:', error));
<?php
function generateRandomPixels($apiKey, $width = 300, $height = 300) {
$url = 'https://api.pixlab.io/pixelgenerate';
$params = [
'key' => $apiKey,
'width' => $width,
'height' => $height
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . '?' . 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 Exception('Curl error: ' . curl_error($ch));
}
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
throw new Exception($reply['error']);
}
return $reply['ssl_link'];
}
try {
$apiKey = 'PIXLAB_API_KEY';
$imageUrl = generateRandomPixels($apiKey);
echo "Randomly generated image location: " . $imageUrl;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
exit(1);
}
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://api.pixlab.io/pixelgenerate')
params = {
'key' => 'PIXLAB_API_KEY',
'width' => 300,
'height' => 300
}
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']
exit
end
puts "Randomly generated image location: #{reply['ssl_link']}"
Similar API Endpoints
newimage nsfw, sfw, ocr, facedetect, docscan, grayscale, rotate, crop, tagimg, mogrify, blur, faceverify ↗, facelookup ↗