API Endpoint Access URL
https://api.pixlab.io/newimage
Get Your API Key & Try NEWIMAGE Now ↗Description
Create and customize new images with specific width, height, and background color using the NEWIMAGE API endpoint. Perfect for developers and creators looking to generate dynamic visuals, including mimicking Facebook-style messages. Dynamically create a new image with a desired width, height and background color. You can invoke for example the drawtext endpoint after the freshly created image is returned to mimic facebook visual messages (See python example below).
HTTP Methods
GET
HTTP Parameters
Fields | Type | Description |
---|---|---|
width |
Integer | Desired image width. If omitted, the height parameter is used as the width value. |
height |
Integer | Desired image height. If omitted, the width parameter is used as the height value. |
key |
String | Your PixLab API Key ↗. Alternatively, you can pass it via the WWW-Authenticate: HTTP header and omit this parameter. |
Optional
Fields | Type | Description |
---|---|---|
blob |
Boolean | Returns raw image binary data when set to true. Default behavior returns a JSON Object with the output URL. |
color |
String | Background color (e.g., white , green ). Defaults to gray . Use tr for transparency or hex codes like #cef48e . |
export |
Format | Output format (default: PNG). Supported: JPEG , BMP , etc. |
HTTP Response
The response content type is 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 are returned directly. The following fields are included in the JSON response body:
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. |
Code Samples
import requests
import sys
def create_image(width: int, height: int, color: str, api_key: str) -> str:
"""Create a new image with specified dimensions and background color."""
response = requests.get(
'https://api.pixlab.io/newimage',
params={
'key': api_key,
'width': width,
'height': height,
'color': color
}
)
response.raise_for_status()
data = response.json()
if data['status'] != 200:
raise ValueError(data.get('error', 'Unknown error creating image'))
return data['link']
def draw_text(image_url: str, text: str, api_key: str, **kwargs) -> str:
"""Draw text on an existing image."""
params = {
'img': image_url,
'key': api_key,
'text': text,
**kwargs
}
response = requests.get('https://api.pixlab.io/drawtext', params=params)
response.raise_for_status()
data = response.json()
if data['status'] != 200:
raise ValueError(data.get('error', 'Unknown error drawing text'))
return data['link']
def main():
API_KEY = 'My_PIXLAB_API_KEY'
try:
image_url = create_image(300, 300, 'yellow', API_KEY)
result_url = draw_text(
image_url,
'bonjour',
API_KEY,
cap=True,
color='black',
font='wolf',
center=True
)
print(f"Pic location: {result_url}")
except (requests.RequestException, ValueError) as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
main()
async function createAndDrawImage() {
try {
// Create a new image
const newImageResponse = await fetch('https://api.pixlab.io/newimage?key=My_PIXLAB_API_KEY&width=300&height=300&color=yellow');
const newImageData = await newImageResponse.json();
if (newImageData.status !== 200) {
console.error(newImageData.error);
return;
}
const img = newImageData.link;
// Draw text on the image
const drawTextResponse = await fetch(`https://api.pixlab.io/drawtext?img=${img}&key=My_PIXLAB_API_KEY&cap=true&color=black&font=wolf¢er=bonjour`);
const drawTextData = await drawTextResponse.json();
if (drawTextData.status !== 200) {
console.error(drawTextData.error);
} else {
console.log("Pic location: " + drawTextData.link);
}
} catch (error) {
console.error('Error:', error);
}
}
createAndDrawImage();
<?php
$apiKey = 'My_PIXLAB_API_KEY';
// Create a new image
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/newimage?key=' . urlencode($apiKey) . '&width=300&height=300&color=yellow');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
die($reply['error']);
}
$img = $reply['link'];
// Draw text on the image
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/drawtext?key=' . urlencode($apiKey) . '&img=' . urlencode($img) . '&cap=true&color=black&font=wolfยขer=bonjour');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
die($reply['error']);
} else {
echo "Pic location: " . $reply['link'];
}
require 'net/http'
require 'uri'
require 'json'
# Dynamically create a 300x300 PNG image with a yellow background
uri = URI.parse('https://api.pixlab.io/newimage')
params = {
'key' => 'My_PIXLAB_API_KEY',
'width' => 300,
'height' => 300,
'color' => 'yellow'
}
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
# Link to the new image
img = reply['link']
# Draw some text now on the new image
uri = URI.parse('https://api.pixlab.io/drawtext')
params = {
'img' => img,
'key' => 'My_PIXLAB_API_KEY',
'cap' => true,
'color' => 'black',
'font' => 'wolf',
'center' => 'bonjour'
}
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 "Pic location: #{reply['link']}"
end
Similar API Endpoints
scale, minify, magnify, crop, resize, smartresize, remap, resample, thumbnail, merge, composite, avatar, mogrify, drawtext