Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New (since 10.1.0) font display is worse than "better than nothing font" for small sizes #8084

Closed
dhylands opened this issue May 26, 2024 · 3 comments · Fixed by #8086
Closed

Comments

@dhylands
Copy link

I'm using a small (128x32) OLED display, which is setup as 4 lines of text on a Raspberry Pi 5 running Ubuntu Server 24.04 LTS.

What did you do?

Upgraded my version of pillow (to any version from 10.1.0 or later)

What did you expect to happen?

My display to be readable.

What actually happened?

Some text is unreadable. In particular, the 6's look almost the same as 8's

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 22.04 and 24.04
  • Python: 3.9.19, 3.10.12, 3.12.3
  • Pillow: 10.3.0
Pillow 10.3.0
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0]
--------------------------------------------------------------------
Python executable is /home/dhylands/adafruit-oled-ssd1306/.direnv/python-3.12.3/bin/python3
Environment Python files loaded from /home/dhylands/adafruit-oled-ssd1306/.direnv/python-3.12.3
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/dhylands/adafruit-oled-ssd1306/.direnv/python-3.12.3/lib/python3.12/site-packages/PIL
Binary Pillow modules loaded from /home/dhylands/adafruit-oled-ssd1306/.direnv/python-3.12.3/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.13, harfbuzz 8.4.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
from PIL import Image, ImageFont, ImageDraw

font = ImageFont.load_default(size=10)

line1 = "IP: 192.168.1.4"
line2 = "CPU load: 0.15"
line3 = "Mem: 341/7942 MB  4.29%"
line4 = "Disk: 2/58 GB  5%"

top = -2

image = Image.new("1", (128, 32))
draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, 128, 32), outline=0, fill=0)
draw.text((0, top + 0), line1, font=font, fill=255)
draw.text((0, top + 8), line2, font=font, fill=255)
draw.text((0, top + 16), line3, font=font, fill=255)
draw.text((0, top + 25), line4, font=font, fill=255)

image.save("display.png")

Image from version 10.0.1 using ImageFont.load_default()
display-better-than-nothing

Image from version 10.3.0 using ImageFont.load_default() (same results seen using 10.1.0 or later)
display-default

Image from 10.3.0 using ImageFont.load_default(size=8)
display-8

Image from 10.3.0 using ImageFont.load_default(size=9)
display-9

Image from 10.3.0 using ImageFont.load_default(size=10)
display-10

@radarhere radarhere changed the title New (since 10.1.0) font display is worse than "better than nothig font" for small sizes New (since 10.1.0) font display is worse than "better than nothing font" for small sizes May 26, 2024
@radarhere
Copy link
Member

If our default font isn't suitable for your purposes, would the easiest solution not be to simply find another font to use? Or are you requesting that provide a way to access to the previous default font?

@dhylands
Copy link
Author

I guess I'm asking for a way to access the previous default font.
I'm dubious that raterizing a vector font is going to give decent results for characters that are only 8 pixels high, but I'm not a font expert.

@radarhere
Copy link
Member

I've created #8086, to add ImageFont.load_default_imagefont().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants