The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 83,381โ€…    Votes:  5โ€…
Tags: image   python-3.x   fonts   python-imaging-library  
Link: ๐Ÿ” See Original Answer on Stack Overflow โง‰ ๐Ÿ”—

Title: PIL Issue, OSError: cannot open resource
ID: /2020/08/01/PIL-Issue_-OSError_-cannot-open-resource
Created: August 1, 2020
Upload: September 20, 2023    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

For Linux I used:

$ locate .ttf


It actually returned A LOT MORE than that!

Then I took the python code posted here in Stack Overflow:

Plugged in the font name โ€œUbuntu-R.ttfโ€ returned by locate:

color_palette = [BLUE, GREEN, RED]
region = Rect(0, 0, image_w, image_h)
imgx, imgy = region.max.x+1, region.max.y+1
image ="RGB", (imgx, imgy), WHITE)
draw = ImageDraw.Draw(image)
vert_gradient(draw, region, gradient_color, color_palette)
#image.text((40, 80),"No Artwork",(255,255,255))
#font = ImageFont.truetype(r'C:\Users\System-Pc\Desktop\arial.ttf', 40)
#font = ImageFont.load_default()
font = ImageFont.truetype("Ubuntu-R.ttf", int(float(image_w) / 6))
draw.text((int(image_w/12), int(image_h / 2.5)), "No Artwork", \
           fill=(0,0,0), font=font)

And voila! I now have an image to display when there is no image to display in a music file Iโ€™m playing:

No Artwork.png

โ‡ง How to make a Tkinter window jump to the front? I need to re-connect HDMI everytime after boot  โ‡ฉ