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

freetype.ft_errors.FT_Exception: FT_Exception: (cannot open resource) #98

Closed
jeff5048 opened this issue Jul 4, 2018 · 2 comments
Closed

Comments

@jeff5048
Copy link

jeff5048 commented Jul 4, 2018

Hi,

I am new to Python programming. I don't know where else to post this issue. I installed freetype like this:
python -m pip install --user freetype-py

It seemed to install okay.

There is an error when the following code is run in IDLE:

import freetype
face = freetype.Face("Vera.ttf")
face.set_char_size( 48*64 )
face.load_char('S')
bitmap = face.glyph.bitmap
print (bitmap.buffer)

I suspect there is no "Vera.ttf" file. The code doesn't work for common windows "ttf" files. Do fonts need to be moved to a specific directory?

Windows 10 Pro
64-bit OS and processor

The error is:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.

= RESTART: C:\Users\jeff5\Desktop\Python\OpenGL_Exercises\freetypeExample.py =
Traceback (most recent call last):
File "C:\Users\jeff5\Desktop\Python\OpenGL_Exercises\freetypeExample.py", line 2, in
face = freetype.Face("Vera.ttf")
File "C:\Users\jeff5\AppData\Roaming\Python\Python36\site-packages\freetype_init_.py", line 989, in init
if error: raise FT_Exception( error )
freetype.ft_errors.FT_Exception: FT_Exception: (cannot open resource)

@madig
Copy link
Collaborator

madig commented Jul 4, 2018

Hi!
If you want to run the code from IDLE, you probably need to specify the full path to a TTF you want to render, try e.g.

import freetype
face = freetype.Face(r'C:\Windows\Fonts\arial.ttf')
face.set_char_size( 48*64 )
face.load_char('S')
bitmap = face.glyph.bitmap
print (bitmap.buffer)

Note the r in front of 'C:\Windows\Fonts\arial.ttf', this makes Windows paths work in Python.

@jeff5048
Copy link
Author

jeff5048 commented Jul 4, 2018

Thank you madig. That did work! I was also able to get it to work by placing a ttf file in the directory with the example code file. It is outputting a bunch of comma delimited numbers to the Python 3.6.5 shell. The "r" before the path is a useful tip as I did not know that. Thx!

@jeff5048 jeff5048 closed this as completed Jul 4, 2018
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

2 participants