drawlineshttps://api.pixlab.io/drawlines
Description
Draw as much lines as desired on a given input image.
HTTP Methods
POST
Request 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 command 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-Type:
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'
}
]
Response
application/json if the optional blob parameter is not set.
This command return 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 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 image ID. |
error | String | Error message if status != 200. |
Python Example
#Draw two lines (one white & one red) on Jeremy's face
import requests
import json
req = requests.post('https://api.pixlab.io/drawlines',headers={'Content-Type':'application/json'},data=json.dumps({
'img': 'http://cf.broadsheet.ie/wp-content/uploads/2015/03/jeremy-clarkson_3090507b.jpg',
'key':'My_PixLab_Key',
'lines': [{
"startx": 200,
"starty": 290,
"endx": 452,
"endy": 375
},{
"startx": 85,
"starty": 60,
"endx": 290,
"endy": 175,
"color": "red"
}]
}))
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
else:
print ("Pic location: "+ reply['link'])