API Endpoint Access URL
https://api.pixlab.io/drawlines
Get Your API Key & Try DRAWLINES Now ↗Description
The Draw Lines API endpoint allows developers to render multiple coordinate-based geometric lines onto an image canvas in a single call. This is highly efficient for drawing polylines, trace paths, grid systems, or complex boundary markups.
HTTP Methods
POST
HTTP Parameters
Required
| Fields | Type | Description |
|---|---|---|
img |
URL | Input image URL. If you want to upload your image directly from your app, call store before invoking this one. |
lines |
Array | JSON array holding the coordinates of the lines to be drawn (See below). |
key |
String | Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to. |
Optional
| Fields | Type | Description |
|---|---|---|
blob |
Boolean | By default, this API endpoint return a JSON Object holding the link to the image output. But, if this parameter is set to true then the image binary contents is returned instead. |
color |
String |
Global color to apply for each line to be drawn which default to white. Use hex color code such as #cef45f if you want to.
|
strokewidth |
Float | Global line stroke width which default to 2. |
strokeopacity |
Float | Global line stroke opacity which default to 0.9. |
POST Request Body
Allowed Content-Types:
application/json
Only JSON data is allowed. The field of interest here is the lines parameter which must be a JSON array holding the object coordinates of each line to be drawn on the input image. The following are the required parameters for each object in the line array:
| Fields | Type | Description |
|---|---|---|
startx |
Integer | Starting X coordinate of this line. |
starty |
Integer | Starting Y coordinate of this line. |
endx |
Integer | Ending X coordinate of this line. |
endy |
Integer | Ending Y coordinate of this line. |
color |
String |
Optional color to apply for this specific line which default to white. Use hex color code such as #cef45f if you want to.
|
So, a typical line array should look like this (See the example section for a working snippet).
lines = [
{
startx: 200,
starty: 290,
endx: 452,
endy: 375
},
{
startx: 85,
starty: 60,
endx: 290,
endy: 175,
color: 'red'
}
]
HTTP Response
Returns application/json if the optional blob parameter is not set.
This endpoint returns a JSON Object after each call unless the blob parameter is specified, in which case the raw image binary is returned. The JSON response contains the following fields:
| Fields | Type | Description |
|---|---|---|
status |
Integer | Status code 200 indicates success, any other code indicates failure. |
link |
URL | Link to the output image stored on the pixlab.xyz server unless custom S3 keys are configured (see console.pixlab.io for setup). |
id |
String | Unique image identifier. |
error |
String |
Error message if status != 200.
|
Code Samples
import requests
import json
def draw_lines_on_image(image_url: str, api_key: str, lines: list) -> str:
"""Draw lines on an image using PixLab API.
Args:
image_url: URL of the image to process
api_key: PixLab API key
lines: List of line dictionaries with coordinates and colors
Returns:
URL of the processed image or error message
"""
endpoint = 'https://api.pixlab.io/drawlines'
headers = {'Content-Type': 'application/json'}
payload = {
'img': image_url,
'key': api_key,
'lines': lines
}
try:
response = requests.post(
endpoint,
headers=headers,
data=json.dumps(payload),
timeout=10
)
response.raise_for_status()
data = response.json()
if data.get('status') == 200:
return data.get('link', '')
return data.get('error', 'Unknown error occurred')
except requests.exceptions.RequestException as e:
return f"Request failed: {str(e)}"
if __name__ == '__main__':
image_url = 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg'
api_key = 'PIXLAB_API_KEY'
lines = [
{
"startx": 200,
"starty": 290,
"endx": 452,
"endy": 375,
"color": "white"
},
{
"startx": 85,
"starty": 60,
"endx": 290,
"endy": 175,
"color": "red"
}
]
result = draw_lines_on_image(image_url, api_key, lines)
if result.startswith('http'):
print(f"Pic location: {result}")
else:
print(f"Error: {result}")
fetch('https://api.pixlab.io/drawlines', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
img: 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
key: 'PIXLAB_API_KEY',
lines: [{
startx: 200,
starty: 290,
endx: 452,
endy: 375
}, {
startx: 85,
starty: 60,
endx: 290,
endy: 175,
color: 'red'
}]
})
})
.then(response => response.json())
.then(data => {
if (data.status !== 200) {
console.log(data.error);
} else {
console.log("Pic location: " + data.link);
}
})
.catch(error => console.error('Error:', error));
<?php
$data = [
'img' => 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
'key' => 'PIXLAB_API_KEY',
'lines' => [
[
'startx' => 200,
'starty' => 290,
'endx' => 452,
'endy' => 375
],
[
'startx' => 85,
'starty' => 60,
'endx' => 290,
'endy' => 175,
'color' => 'red'
]
]
];
$ch = curl_init('https://api.pixlab.io/drawlines');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
echo "Pic location: " . $reply['link'];
}
require 'net/http'
require 'uri'
require 'json'
uri = URI.parse('https://api.pixlab.io/drawlines')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-Type'] = 'application/json'
request.body = {
'img' => 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
'key' => 'PIXLAB_API_KEY',
'lines' => [
{
'startx' => 200,
'starty' => 290,
'endx' => 452,
'endy' => 375
},
{
'startx' => 85,
'starty' => 60,
'endx' => 290,
'endy' => 175,
'color' => 'red'
}
]
}.to_json
response = http.request(request)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
puts "Pic location: #{reply['link']}"
end
Similar API Endpoints
drawrectangles, drawcircles, drawtext, drawpoints, drawtextat