2017-12-07 21 views
1

イメージにテキストを配置するプログラムを作成しようとしていますが、私はPILに頭を向けようとしていて、OSError:リソースをオープンできません。これは私の最初のpythonプログラムですので、エラーが明らかであれば謝ります。PIL Issue、OSError:リソースを開くことができません

from PIL import Image 
from PIL import ImageDraw 
from PIL import ImageFont 


im = Image.open("example.jpg") 
font_type = ImageFont.truetype("Arial.ttf", 18) 
draw = ImageDraw.Draw(im) 
draw.text(xy=(50, 50), text= "Text One", fill =(255,69,0), font = font_type) 
im.show() 

私はエラーを取得する:

Traceback (most recent call last): 
File "C:\Users\laurence.maskell\Desktop\attempt.py", line 7, in <module> 
font_type = ImageFont.truetype("Arial.ttf", 18) 
File "C:\Python34\lib\site-packages\PIL\ImageFont.py", line 259, in truetype 
return FreeTypeFont(font, size, index, encoding, layout_engine) 
File "C:\Python34\lib\site-packages\PIL\ImageFont.py", line 143, in __init__ 
self.font = core.getfont(font, size, index, encoding, 
layout_engine=layout_engine) 
OSError: cannot open resource 
+0

'ImageFont.truetype'の' r "C:\ Windows \ Fonts \ Arial.ttf"のようなフォントにフルパスを設定してみてください。 –

答えて

0

PILは、指定されたフォントを見つけることができません。それが存在することと、まったく同じケースで命名されていることを確認してください。 プロジェクトフォルダに直接コピーすることもできます。

関連する問題