Version 1.9.72 (Release Notes)


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

FieldsTypeDescription
widthIntegerDesired Image width. If this field is missing, then the height parameter is applied for this one.
heightIntegerDesired Image height. If this field is missing, then the width parameter is applied for this one.
keyStringYour PixLab API Key. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to.

Optional
FieldsTypeDescription
blobBooleanBy 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.
colorStringDesired 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.
exportFormatOutput 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:

FieldsTypeDescription
statusIntegerStatus code 200 indicates success, any other code indicates failure.
linkURLLink 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).
idStringUnique media ID.
errorStringError 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