在阅读了大量的枕头文档、堆栈溢出和web之后,我一直无法破译这个错误消息,因为它正在丢弃我的应用程序。我当前的设置:
下面是我一直在做的一个可验证的例子。本质上,我的错误发生在我使用title_font
代替default_font
时。2条评论强调:# TODO Aborts with error unless using default_font TODO
from PIL import ImageFont, ImageDraw, Image
def app():
# Default Font with static size and font type
default_font = ImageFont.load_default()
# TODO Title Font that is the desired use
title_font = ImageFont.truetype(font="~/Library/Fonts/Verdana.ttf", size=36)
# Background Image to draw text on
bg_img = Image.new(mode = "RGBA",size = (3480,2160), color="Green")
# Creates an object that can be used to draw in the given image.
d = ImageDraw.Draw(bg_img)
txt = "Hello World"
# TODO: Aborts with error unless using default_font TODO
# Returns (width, height) of text in pixels with designated font
txt_width, txt_height = default_font.getsize(txt)
print(f"Text Width:{txt_width} Text Height: {txt_height}")
# TODO: Aborts with error unless using default_font TODO
# Draws "Hello World" onto background image
d.text((10,60), text=txt, font=default_font, fill=(255,255,255,255))
# Pop Up window
bg_img.show()
下面是我从ImageDraw/ImageFont两种方法中得到的error message:
>>> app()
dyld: lazy symbol binding failed: Symbol not found: _hb_language_get_default
Referenced from: /usr/local/lib/libraqm.dylib
Expected in: flat namespace
dyld: Symbol not found: _hb_language_get_default
Referenced from: /usr/local/lib/libraqm.dylib
Expected in: flat namespace
我已经试过:
ImageFont.load_default()
来解决问题,但是您可以通过运行它来判断,默认字体非常小,无法更改其大小或样式我不确定的最后一件事是安装指南中的这一行,它是在包的brew install
之后推荐的:
然后请参阅depends/install_raqm_cmake.sh以安装libraqm。
可以在Building on macOS部分的中间找到。我有一种唠叨的感觉,这可能是原因,但我根本不明白它希望我采取什么行动
长期潜伏者,第一次海报。感谢你现在的任何帮助和多年来给予我的所有帮助
更新:在另一台MacBook上使用了我的示例,效果很好。我将重置它不工作的那台,并从头开始构建。感谢您的帮助!
我假设您(和我一样)使用了带有OS Catalina或类似操作系统的Mac,并且可能也安装了带有“$brew install libraqm”的所述库
我通过更改布局引擎解决了这个问题,因此,在后台不使用“libraqm”进行PIL布局工作
如果您这样做,您可能无法使用中文或类似字体。我不确定“brew”、“pyenv”或“libraqm”中的问题在哪里,但我尝试找出它
相关问题 更多 >
编程相关推荐