API Endpoint Access URL
https://api.pixlab.io/avatar
Get Your API Key & Try AVATAR Now ↗Description
Generate a 100x75px thumbnail perfectly suited to use as avatar. This API endpoint is a just wrapper around thumbnail with width & height set respectively to 100 and 75.
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input media URL. If uploading directly from your app, submit a multipart/form-data POST request. |
key |
String | Your PixLab API Key ↗. Alternatively, embed it in the WWW-Authenticate: header and omit this parameter. |
Optional
Fields | Type | Description |
---|---|---|
blob |
Boolean | Returns JSON with output image link by default. Set to true to receive binary media content instead. |
POST Request Body
This section details the requirements for using a POST request instead of a simple GET request.
Allowed Content-Types:
multipart/form-data
application/json
Use multipart/form-data
for direct file uploads (see examples). For JSON, ensure the media is already hosted elsewhere. Upload images via store before invoking this endpoint if needed.
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 API endpoint returns a JSON Object after each call only if the optional blob parameter is omitted. Otherwise, the image binary content is returned directly. The JSON response contains the following fields:
Code Samples
import requests
def generate_avatar(image_url: str, api_key: str) -> str:
"""Generate an avatar from an image using PixLab API.
Args:
image_url: URL of the source image
api_key: PixLab API key
Returns:
URL of the generated avatar
Raises:
requests.exceptions.RequestException: If API request fails
ValueError: If API returns an error
"""
try:
response = requests.get(
'https://api.pixlab.io/avatar',
params={
'img': image_url,
'key': api_key
},
timeout=10
)
response.raise_for_status()
data = response.json()
if data.get('status') != 200:
raise ValueError(data.get('error', 'Unknown error from API'))
return data['link']
except requests.exceptions.RequestException as e:
raise requests.exceptions.RequestException(f"API request failed: {e}")
except json.JSONDecodeError:
raise ValueError("Invalid JSON response from API")
if __name__ == "__main__":
try:
avatar_url = generate_avatar(
image_url='http://www.drodd.com/images15/nature31.jpg',
api_key='My_PIXLAB_API_KEY'
)
print(f"Avatar location: {avatar_url}")
except Exception as e:
print(f"Error generating avatar: {e}")
fetch('https://api.pixlab.io/avatar?img=http://www.drodd.com/images15/nature31.jpg&key=My_PIXLAB_API_KEY')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Pic location: " + reply.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$params = [
'img' => 'http://www.drodd.com/images15/nature31.jpg',
'key' => 'My_PIXLAB_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/avatar?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
die('Curl error: ' . curl_error($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 'json'
uri = URI('https://api.pixlab.io/avatar')
params = {
'img' => 'http://www.drodd.com/images15/nature31.jpg',
'key' => 'My_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 "Pic location: #{reply['link']}"
end
Similar API Endpoints
scale, minify, magnify, crop, resize, smartresize, remap, resample, thumbnail, merge, composite, webfit, emailfit, msgfit, favicon, screencapture