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

Python PIL OSError: invalid pixel size #142

Open
youasscoder opened this issue Dec 28, 2023 · 4 comments
Open

Python PIL OSError: invalid pixel size #142

youasscoder opened this issue Dec 28, 2023 · 4 comments

Comments

@youasscoder
Copy link

font = ImageFont.truetype(font_path, font_size)
no size gives me no "OSError: invalid pixel size"
python PIL

@youasscoder youasscoder changed the title OSError: invalid pixel size Python PIL OSError: invalid pixel size Dec 28, 2023
@HinTak
Copy link

HinTak commented Feb 6, 2024

I think that's an error from freetype - and it is what it says, invalid pixel size. Some bitmap color fonts (sbix and CBDT) contains bitmaps designed for specific sizes, and if you ask for pixel sizes not in one of the designed values, FreeType gives you that error. You can use "ftdump" to get a list of what valid sizes are.

@13rac1
Copy link
Owner

13rac1 commented Feb 18, 2024

How is this error related to this font?

@HinTak
Copy link

HinTak commented Feb 18, 2024

From that error message, I would assume that PIL's ImageFont.truetype() uses freetype to load this font, and PIL can't use the SVG table, so it is reading the sbix or CBDT table only of this font, which are of specific pixel sizes.

I thought I have written a README.md about it, but perhaps I have only written to freetype-devel: if you have either pycairo or skia-python available, you can make any freetype-py using program (and I believe PIL being one) support SVG-OT with either https://github.com/HinTak/harfbuzz-python-demos/blob/master/otsvg.py or https://github.com/HinTak/harfbuzz-python-demos/blob/master/skia_ot_svg_module.py .

These two basically enable any freetype-py using python programs to read SVG-OT fonts. And SVG-OT being any-pixel-size, it gets around the sbix/CBDT fixed-pixel-size limitations.

You might have to ask PIL people how to hook the two modules in - it depends on how PIL uses freetype-py/freetype.

@HinTak
Copy link

HinTak commented Feb 18, 2024

Okay, I looked at PIL in my hard disk - it uses freetype directly via _imagingft.cpython.....so. You'll need to contact the PIL people directly, essentially with the above info. They need to hook up the C-equivalent of that python code. There are again two versions of it, the cairo-dependent version is upstream in ft2-demos, while the skia-dependent version only exists as a patch and is posted at https://github.com/HinTak/harfbuzz-python-demos/tree/master/skia-adventure, with a README.md describing it.

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

No branches or pull requests

3 participants