PIL Fonts

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

PIL Fonts

clive sinclair
I am running Python 2.6 and have just installed PIL 1.1.7 running on Win
2000.

When I try to get a font object eg by
font = ImageFont.truetype("C:\WINNT\Fonts\arial.ttf", 15)
I get an exception
   File "C:\Python26\lib\site-packages\PIL\ImageFont.py", line 134, in
__init__
     self.font = core.getfont(file, size, index, encoding)
IOError: cannot open resource.

Looking into Class FreeTypeFont I see that _imagingft service is
required. This file is present in C:\Python26\Lib\site-packages\PIL.
Should this file be installed during the Python2.6 setup? What should I
do to fix this problem? I had basically the same problem with PIL 1.1.6.

C Sinclair


_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: PIL Fonts

Fredrik Lundh
On Sat, Mar 20, 2010 at 9:10 PM, clive sinclair
<[hidden email]> wrote:

> I am running Python 2.6 and have just installed PIL 1.1.7 running on Win
> 2000.
>
> When I try to get a font object eg by
> font = ImageFont.truetype("C:\WINNT\Fonts\arial.ttf", 15)
> I get an exception
>  File "C:\Python26\lib\site-packages\PIL\ImageFont.py", line 134, in
> __init__
>    self.font = core.getfont(file, size, index, encoding)
> IOError: cannot open resource.
>
> Looking into Class FreeTypeFont I see that _imagingft service is required.
> This file is present in C:\Python26\Lib\site-packages\PIL.
> Should this file be installed during the Python2.6 setup? What should I do
> to fix this problem? I had basically the same problem with PIL 1.1.6.

Python interprets the "\a" in your string as a control character:

>>> "C:\WINNT\Fonts\arial.ttf"
'C:\\WINNT\\Fonts\x07rial.ttf'

See

    http://docs.python.org/reference/lexical_analysis.html#string-literals

for a list of such escape codes.

To fix this, use forward slashes (they work on both Unix and Windows),
double the backslashes, or use "raw" strings.  Your favourite Python
tutorial should have more information on how to work with file names.

</F>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig