首页 > 其他分享 >pillow ImageFont.truetype OSError: cannot open resource

pillow ImageFont.truetype OSError: cannot open resource

时间:2023-10-08 10:33:06浏览次数:31  
标签:engine OSError resource encoding truetype ImageFont PIL font layout

 

from PIL import ImageFont, ImageDraw
# 导入中文字体,指定字体大小
font = ImageFont.truetype('SimHei.ttf', 50)
OSError                                   Traceback (most recent call last)
/tmp/ipykernel_4385/1341045620.py in <module>
      1 from PIL import ImageFont, ImageDraw
      2 # 导入中文字体,指定字体大小
----> 3 font = ImageFont.truetype('SimHei.ttf', 50)

/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/PIL/ImageFont.py in truetype(font, size, index, encoding, layout_engine)
   1006 
   1007     try:
-> 1008         return freetype(font)
   1009     except OSError:
   1010         if not is_path(font):

/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/PIL/ImageFont.py in freetype(font)
   1003 
   1004     def freetype(font):
-> 1005         return FreeTypeFont(font, size, index, encoding, layout_engine)
   1006 
   1007     try:

/home/software/anaconda3/envs/tf115/lib/python3.7/site-packages/PIL/ImageFont.py in __init__(self, font, size, index, encoding, layout_engine)
    254                     return
    255             self.font = core.getfont(
--> 256                 font, size, index, encoding, layout_engine=layout_engine
    257             )
    258         else:

OSError: cannot open resource

 

解决方法:

补全字体的路径(绝对路径)。

/path/to/this/file/SimHei.ttf', 50)



标签:engine,OSError,resource,encoding,truetype,ImageFont,PIL,font,layout
From: https://blog.51cto.com/emanlee/7750850

相关文章

  • Spring中@Autowired和@Resource的区别
    说明@Autowired这个注解呢,是由Spring提供的;@Resource由JDK提供的区别①注解内参数不同@Autowired只包含一个required参数,默认为true,表示开启自动注入@Resource包含七个参数,其中最重要的两个是name和type②装配方式默认值不同@Autowired默认按type自动装配@Resource默认按......
  • try-with-resources语句
    try-with-resources语句try-with-resources语句是一种声明了一种或多种资源的try语句。资源是指在程序用完了之后必须要关闭的对象。try-with-resources语句保证了每个声明了的资源在语句结束的时候都会被关闭。任何实现了java.lang.AutoCloseable接口的对象,和实现了java.io.Clos......
  • Java内存分析工具实践之resourcemanager内存泄漏排查
    ......
  • 全面正确理解 @Autowired 和 @Resource
    @Autowired和@Resource都是Spring/SpringBoot项目中,用来进行依赖注入的注解。他们的区别主要是下面几点:1.来源不同;2.依赖查找的顺序不同;3.支特的参数不同;4.依赖注入的用法不同:一、来源不同。@Autowire是来自spring的注解,@Resource是来自Java的注解......
  • 为什么@Resource无法注入泛型类型而@Autowired可以
    在Spring框架中,我们通常使用@Autowired和@Resource两个注解来实现属性注入。但是当涉及到泛型类型时,使用@Resource注解就会失败,而@Autowired可以正常工作。这篇文章就来分析它们之间的区别。@Autowired可以直接注入泛型类型,例如:```java@AutowiredprivateRepository<User>......
  • [Spring]浅谈Spring的Resources体系
    Spring为什么要创建Resources体系Java的标准java.net.url类和各种URL前缀的标准处理程序无法满足所有对low-level资源的访问.举个例子:没有标准化的URL实现类用于获取根据ServletContext的类路径。并且缺少某些Spring所需要的功能,例如检测某资源是否存在等。ResourceSpring的Resour......
  • class path resource [.xml] cannot be opened because it does not exist
    classpathresource[bean1.xml]cannotbeopenedbecauseitdoesnotexist错误重现bug:Exceptioninthread"main"org.springframework.beans.factory.BeanDefinitionStoreException:IOExceptionparsingXMLdocumentfromclasspathresource[bean1.xml]......
  • 解决pycharm报错:_jb_pytest_runner.py:7:....from pkg_resources import iter_entry_p
    遇到问题执行pytest用例出现警告D:\pycharm\PyCharm2020.1.5\plugins\python\helpers\pycharm_jb_pytest_runner.py:7:DeprecationWarning:pkg_resourcesisdeprecatedasanAPI.Seehttps://setuptools.pypa.io/en/latest/pkg_resources.htmlfrompkg_resourcesimport......
  • Resource文件夹(转)
    转自:#Assets-Unity为何不建议使用ResourcesFolder?-简书(jianshu.com)最近换项目,中间有了几天“间歇期”,正好可以抽空读一读这篇文章,读起来并不轻松,英语水平有限,尝试理解其中的含义概念,有些段落反反复复看了多次,在这里把笔记分享出来,这也是对知识的一次总结。初学Unity......
  • 关于使用LoadResource、EndUpdateResource的问题
    需要操作资源DLL中的资源,自作聪明的将其写成一个如下的类://---------------------------------------------------------------------------#ifndefUnit2H#defineUnit2H#include<windows.h>#include<assert.h>//-------------------------------------------------------......