from PIL import Image
from PIL import ImageFilter
from PIL import ImageEnhance
from PIL import ImageDraw , ImageFont
im = Image.open('紫卡.jpg')
draw = ImageDraw.Draw(im)
fnt = ImageFont.truetype(r'C:\Windows\Fonts\STXINGKA.TTF',20)
draw.text((217,233), u'南理',font=fnt ,fill='red' )
im.show()
im.save(初版图片.jpg)
想用py圖片新增文字,上網查了一下,並稍改他的範例,執行結果失敗
Traceback (most recent call last):
File "main", line 11, in <module>
fnt= ImageFont.truetype(r'C:\Windows\Fonts\STXINGKA.TTF',20)
File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\ImageFont.py", line 275, in truetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\ImageFont.py", line 144, in __init__
self.font = core.getfont(font, size, index, encoding, layout_engine=layout_engine)
OSError: cannot open resource
實在不理解,有方法解決嗎
參考網站:https://blog.csdn.net/dyyay521/article/details/102546637