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