I have written now 2-3 API programs in starlark - and it’s not my style. Can’t read or write files to disk and many of the functions are just not as well documented as in Python.
For those who feel similar - install pillow
pip3 install pillow -
and use pillow - e.g.
import os
from PIL import Image, ImageDraw, BdfFontFile, ImageFont
images = []
width = 32
center = 16
center2x = 40
max_radius = int(center * 1.5)
step = 1
#import tidbyt font and convert to pil font
f="/home/pixlet/build/pixlet/fonts/5x8bak.bdf"
fp = open(f, “rb”)
p = BdfFontFile.BdfFontFile(fp)
p.save(f)
font1 = ImageFont.load("/home/pixlet/build/pixlet/fonts/5x8bak.pil")
for i in range(0, max_radius, step):
im = Image.new(‘RGB’, (64, 32), ((i)8, (8-i)8, (i)8))
draw = ImageDraw.Draw(im)
#draw texbox
draw.text((i2,i), “Licence to”, fill=(255,255,i7), font=font1)
draw.text((i2+10,i+10), “Kill”, fill=(255,255,i*7), font=font1)
#draw line
draw.line([(center - i, center - i), (center + i, center + i)], fill=“red”, width = 3 )
#draw circle
draw.ellipse((center2x - i, center - i, center2x + i, center + i), fill=(255,255,255))
images.append(im)
#save webp format
images[0].save(‘pillow1.webp’, ‘webp’,
save_all=True, append_images=images[1:], optimize=False, duration=40, loop=0)
#call shell script to publish using pixlet API
os.system(‘sh /home/pixlet/pubwebp.sh pillow1’)