API Endpoint Access URL
https://api.pixlab.io/drawtextat
Get Your API Key & Try DRAWTEXTAT Now ↗Description
Draw text at a specified offset on a given image using the DRAWTEXTAT API endpoint. Essential for developers and creators looking to enhance image content dynamically. Draw some text at a specified offset of a given image.
HTTP Methods
GET, POST
HTTP Parameters
Required
Fields | Type | Description |
---|---|---|
img |
URL | Input media URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request. |
x |
Integer | Horizontal offset in pixels to the left of text. |
y |
Integer | Vertical offset in pixels to the baseline of text. |
text |
String | Text to draw at the specified offset. (See below for draw options). |
key |
String | Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter. |
Optional
Fields | Type | Description |
---|---|---|
blob |
Boolean | By default, returns JSON with image URL. Set to true to receive binary image data instead. |
font |
String | Font name (default: Impact ). Available fonts: impact , college , bold , square , arial , mario , vera , owl , wolf , gym , dotty , meth , puppy . Register custom fonts via dashboard ↗. |
cap |
Boolean | Capitalize all text characters when true. |
size |
Integer | Font size. |
color |
String | Font color (default: white). Use hex codes (e.g. #cef45f). |
strokecolor |
String | Stroke color (hex code or name e.g. black ). |
strokewidth |
Float | Text stroke width (default: 2 when stroke color is set). |
strokeopacity |
Float | Text stroke opacity (default: 0.9 when stroke color is set). |
POST Request Body
Allowed Content-Types:
multipart/form-data
application/json
Use multipart/form-data
for direct file uploads. For JSON, the media must be pre-uploaded (use store endpoint first).
HTTP Response
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. |
The API returns a JSON response with content type 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 omitted. Otherwise, the raw image binary is returned directly.
Code Samples
import requests
def draw_text_on_image(
image_url: str,
text: str,
x_coord: int,
y_coord: int,
capitalize: bool = True,
stroke_color: str = "black",
api_key: str = "PIXLAB_API_KEY",
) -> str:
"""Draw text on an image using the PixLab API.
Args:
image_url: URL of the image to modify.
text: Text to draw on the image.
x_coord: X coordinate for text position.
y_coord: Y coordinate for text position.
capitalize: Whether to capitalize the text.
stroke_color: Color of the text stroke.
api_key: PixLab API key.
Returns:
URL of the modified image or error message.
"""
params = {
"img": image_url,
"text": text,
"x": x_coord,
"y": y_coord,
"cap": capitalize,
"strokecolor": stroke_color,
"key": api_key,
}
try:
response = requests.get("https://api.pixlab.io/drawtextat", params=params)
response.raise_for_status()
data = response.json()
if data["status"] != 200:
return f"Error: {data.get('error', 'Unknown error')}"
return f"Meme: {data['link']}"
except requests.exceptions.RequestException as e:
return f"Request failed: {str(e)}"
except (KeyError, ValueError) as e:
return f"Failed to process response: {str(e)}"
if __name__ == "__main__":
result = draw_text_on_image(
image_url="https://pixlab.io/images/jdr.jpg",
text="monday morning mood",
x_coord=75,
y_coord=150,
)
print(result)
fetch('https://api.pixlab.io/drawtextat?img=https://pixlab.io/images/jdr.jpg&text=monday morning mood&x=75&y=150&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',
'text' => 'monday morning mood',
'x' => 75,
'y' => 150,
'cap' => true,
'strokecolor' => 'black',
'key' => 'PIXLAB_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pixlab.io/drawtextat?' . 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 "Meme: " . $reply['link'];
}
require 'net/http'
require 'json'
uri = URI('https://api.pixlab.io/drawtextat')
params = {
'img' => 'https://pixlab.io/images/jdr.jpg',
'text' => 'monday morning mood',
'x' => 75,
'y' => 150,
'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
drawtext, merge, nsfw, facedetect, drawrectangles, drawlines, drawpoints, meme, mogrify, crop, rotate