Last active
July 17, 2021 01:35
-
-
Save symisc/fea5db44fd0bc78a5afeab24aab9e443 to your computer and use it in GitHub Desktop.
Dynamically create a 300x300 PNG image with a yellow background and draw some text on its center using the PixLab API - https://pixlab.io/cmdls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
# Dynamically create a 300x300 PNG image with a yellow background and draw some text at the center of it later. | |
# Refer to https://pixlab.io/cmd?id=newimage && https://pixlab.io/cmd?id=drawtext for additional information. | |
req = requests.get('https://api.pixlab.io/newimage',params={ | |
'key':'PIXLAB_API_KEY', # Your PixLab API Key - Get yours from https://pixlab.io/dashboard | |
"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':'PIXLAB_API_KEY', # Your PixLab API Key - Get yours from https://pixlab.io/dashboard | |
"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']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment