API Endpoint Access URL
https://api.pixlab.io/drawtext
Get Your API Key & Try DRAWTEXT Now ↗Description
Draw text on the top, center, or bottom of an image using the DRAWTEXT API endpoint. Perfect for developers and creators looking to enhance image content. Draw some text on Top, Center or Bottom of a given image.
HTTP Methods
GET, POST
HTTP Parameters
Fields | Type | Description |
---|---|---|
img |
URL | Input media URL. If uploading directly from your app, submit a multipart/form-data POST request. |
top |
String | Text to render at top center of the image. |
center |
String | Text to render at center of the image. |
bottom |
String | Text to render at bottom center of the image. |
key |
String | Your PixLab API Key ↗. Alternatively, embed your key in the WWW-Authenticate: HTTP header. |
Fields | Type | Description |
---|---|---|
blob |
Boolean | Returns image binary data when true (default: JSON response with output URL). |
font |
String | Font name (default: Impact ). Available options: impact , college , bold , square , arial , mario , vera , owl , wolf , gym , dotty , meth , puppy . Register custom fonts via the dashboard ↗. |
cap |
Boolean | Capitalizes all text when enabled. |
size |
Integer | Font size in points. |
color |
String | Font color (default: white). Accepts hex codes (e.g., #cef45f). |
strokecolor |
String | Stroke/border color (e.g., black or hex code). |
strokewidth |
Float | Stroke width (default: 2 when strokecolor is set). |
strokeopacity |
Float | Stroke opacity (default: 0.9 when strokecolor is set). |
POST Request Body
Supported Content-Type:
multipart/form-data
(direct file upload)application/json
(requires pre-uploaded media via store)
Refer to the REST API code samples for implementation examples.
HTTP Response
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 instead. The following are the JSON fields
returned in response body:
Fields | Type | Description |
---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
link |
URL | Link to the media 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
def generate_meme(
img_url: str,
top_text: str,
bottom_text: str,
capitalize: bool = True,
stroke_color: str = "black",
api_key: str = "PIXLAB_API_KEY",
) -> str:
"""Generate a meme by adding text to an image using PixLab API.
Args:
img_url: URL of the base image.
top_text: Text to be displayed at the top.
bottom_text: Text to be displayed at the bottom.
capitalize: Whether to capitalize the text.
stroke_color: Color of the text stroke.
api_key: PixLab API key.
Returns:
URL of the generated meme.
Raises:
Exception: If API request fails.
"""
params = {
"img": img_url,
"top": top_text,
"bottom": bottom_text,
"cap": capitalize,
"strokecolor": stroke_color,
"key": api_key,
}
try:
response = requests.get("https://api.pixlab.io/drawtext", params=params)
response.raise_for_status()
data = response.json()
if data["status"] != 200:
raise Exception(data.get("error", "Unknown error occurred"))
return data["link"]
except requests.exceptions.RequestException as e:
raise Exception(f"API request failed: {e}")
if __name__ == "__main__":
try:
meme_url = generate_meme(
img_url="https://pixlab.io/images/jdr.jpg",
top_text="someone bumps the table",
bottom_text="right before you win",
)
print(f"Meme: {meme_url}")
except Exception as e:
print(f"Error: {e}")
fetch('https://api.pixlab.io/drawtext?img=https://pixlab.io/images/jdr.jpg&top=someone bumps the table&bottom=right before you win&cap=true&strokecolor=black&key=PIXLAB_API_KEY')
.then(response => response.json())
.then(reply => {
if (reply.status !== 200) {
console.log(reply.error);
} else {
console.log("Meme: " + reply.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$params = [
'img' => 'https://pixlab.io/images/jdr.jpg',
'top' => 'someone bumps the table',
'bottom' => 'right before you win',
'cap' => true,
'strokecolor' => 'black',
'key' => 'PIXLAB_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/drawtext?' . http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
echo "Meme: " . $reply['link'];
}
require 'net/http'
require 'json'
uri = URI('https://api.pixlab.io/drawtext')
params = {
'img' => 'https://pixlab.io/images/jdr.jpg',
'top' => 'someone bumps the table',
'bottom' => 'right before you win',
'cap' => true,
'strokecolor' => 'black',
'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 "Meme: #{reply['link']}"
end
Similar API Endpoints
drawtextat, merge, nsfw, facedetect, drawrectangles, drawlines, drawpoints, annotate, mogrify, crop, rotate