Skip to content

Instantly share code, notes, and snippets.

@symisc
Created February 11, 2021 00:44
Show Gist options
  • Save symisc/387563f51f8542587c6b2c9a4db45d15 to your computer and use it in GitHub Desktop.
Save symisc/387563f51f8542587c6b2c9a4db45d15 to your computer and use it in GitHub Desktop.
Dynamically generates a set of random pixels of desired width & height using PixLab /pixelgenerate API endpoint - https://pixlab.io/cmd?id=pixelgenerate
import requests
import json
# Generates a set of random pixels of desired Width & Height. 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', # https://pixlab.io/dashboard to get your 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'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment