Version 1.9.72 (Release Notes)


pixelgeneratehttps://api.pixlab.io/pixelgenerate

Description

Generates a set of random pixels. This endpoint is similar to newimage except that the image contents is filled with random pixels. This is very useful for generating background (negative) samples for feeding Machine Learning training algorithms.

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 endpoint return a JSON object holding the link to the generated 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 none. 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

# Generates a set of random pixels. This endpoint is similar to /newimage except that the image contents is filled with random pixels. This is very useful for generating background (negative) samples for feeding Machine Learning training algorithms
req = requests.get('https://api.pixlab.io/pixelgenerate',params={
	'key':'PIXLAB_API_KEY',
	"width":300,
	"height":300
})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
	exit();
#Link to the newly generated image
print ("Randomly generated image location: "+ reply['ssl_link'])

See Also