newimagehttps://api.pixlab.io/newimage
Description
Dynamically create a new image with a desired width, height and background color. You can invoke for example the drawtext endpoint after the freshly created image is returned to mimic facebook visual messages (See python example below).
HTTP Methods
GET
Request Parameters
Required
Fields | Type | Description |
---|---|---|
width | Integer | Desired Image width. If this field is missing, then the height parameter is applied for this one. |
height | Integer | Desired Image height. If this field is missing, then the width parameter is applied for this one. |
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 | Desired background color such as white, green, etc . If this field is missing, then the default background color is gray. If you want a transparent image, then put tr instead. You can also set a color code like #cef48e if you want to. |
export | Format | Output image format. The default is PNG. Otherwise, pass JPEG, BMP, etc. at request. |
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 media ID. |
error | String | Error message if status != 200. |
Python Example
import requests
import json
# Dynamically create a 300x300 PNG image with a yellow background and draw some text at the center of it later.
req = requests.get('https://api.pixlab.io/newimage',params={
'key':'My_Pix_Key',
"width":300,
"height":300,
"color":"yellow"
})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
exit();
#Link to the new image
img = reply['link'];
#Draw some text now on the new image
req = requests.get('https://api.pixlab.io/drawtext',params={
'img':img, #The newly created image
'key':'My_Pix_Key',
"cap":True, #Uppercase
"color":"black", #Text color
"font":"wolf",
"center":"bonjour"
})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
else:
print ("Pic location: "+ reply['link'])
See Also
scale, minify, magnify, crop, resize, smartresize, remap, resample, thumbnail, merge, composite, avatar, mogrify, drawtext