shadowcz007 / comfyui-mixlab-nodes

Workflow-to-APP、ScreenShare&FloatingVideo、GPT & 3D、SpeechRecognition&TTS
https://mixlabnodes.com
MIT License
1.12k stars 67 forks source link

An error occurred on "Text Image" node : 'FreeTypeFontobject' has no attribute 'getsize' #267

Open aidenli opened 2 months ago

aidenli commented 2 months ago

I have updated the newest version and I found an error like this: image

Error occurred when executing TextImage:

'FreeTypeFont' object has no attribute 'getsize'

File "C:\aigc\ComfyUI_windows_portable\ComfyUI\execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\execution.py", line 81, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-mixlab-nodes\nodes\ImageNode.py", line 1546, in run img,mask=generate_text_image(text,font_path,font_size,text_color,vertical,stroke,(0, 0, 0),1,spacing,padding) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-mixlab-nodes\nodes\ImageNode.py", line 943, in generate_text_image line_width, line_height = font.getsize(line)


I looked at line 932 of the ImageNode.py file. The getsize method was no longer defined in ImageFont.py, but was replaced by getbbox. I tried to fix this myself by replacing all getsize with getbox.

Below is the code after I modified ImageNode.py, from line 930 to line 951:

if layout == "vertical":
    for line in lines:
        max_char_width = max(font.getbbox(char)[2] for char in line)
        for char in line:
            left, top, char_width, char_height = font.getbbox(char)
            char_coordinates.append((x, y))
            y += char_height + spacing
            max_height = max(max_height, y + padding)
        x += max_char_width + spacing
        y = padding
    max_width = x
else:
    for line in lines:
        left, top, line_width, line_height = font.getbbox(line)
        for char in line:
            left, top, char_width, char_height = font.getbbox(char)
            char_coordinates.append((x, y))
            x += char_width + spacing
            max_width = max(max_width, x + padding)
        y += line_height + spacing
        x = padding
    max_height = y

BannyLon commented 1 month ago

这是因为安装了新版本的 Pilow ,将getsize 功能降级到 Pillow 9.5 就解决了该问题 可以尝试以下方法进行解决:pip install Pillow==9.5

但是一旦将Pillow 降级到9.5后,就会产生第二个问题:旧版本的Pillow(9.5.0)与另一个已安装的库(psd-tools 1.9.34)不兼容。

选择使用。

BannyLon commented 1 month ago

I have updated the newest version and I found an error like this:

image Error occurred when executing TextImage:

'FreeTypeFont' object has no attribute 'getsize'

File "C:\aigc\ComfyUI_windows_portable\ComfyUI\execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\execution.py", line 81, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-mixlab-nodes\nodes\ImageNode.py", line 1546, in run img,mask=generate_text_image(text,font_path,font_size,text_color,vertical,stroke,(0, 0, 0),1,spacing,padding) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\aigc\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui-mixlab-nodes\nodes\ImageNode.py", line 943, in generate_text_image line_width, line_height = font.getsize(line)

I looked at line 932 of the ImageNode.py file. The getsize method was no longer defined in ImageFont.py, but was replaced by getbbox. I tried to fix this myself by replacing all getsize with getbox.

Below is the code after I modified ImageNode.py, from line 930 to line 951:

if layout == "vertical":
    for line in lines:
        max_char_width = max(font.getbbox(char)[2] for char in line)
        for char in line:
            left, top, char_width, char_height = font.getbbox(char)
            char_coordinates.append((x, y))
            y += char_height + spacing
            max_height = max(max_height, y + padding)
        x += max_char_width + spacing
        y = padding
    max_width = x
else:
    for line in lines:
        left, top, line_width, line_height = font.getbbox(line)
        for char in line:
            left, top, char_width, char_height = font.getbbox(char)
            char_coordinates.append((x, y))
            x += char_width + spacing
            max_width = max(max_width, x + padding)
        y += line_height + spacing
        x = padding
    max_height = y

按照上面的修改后,如果将节点Text Image ♾️Mixlab(文本图像)中的vertical改为false就还会出现这样报错:Error occurred when executing TextImage:'FreeTypeFont' object has no attribute 'getsize'

BannyLon commented 1 month ago

遇到这个问题的朋友可以去这里找完美解决办法:https://www.bilibili.com/opus/961012319932907520

shadowcz007 commented 1 month ago

感谢反馈,我会抽空研究下如何解决

Yuans111 commented 1 month ago

我按照方法操作后报错信息如下 Error occurred when executing TextImage. unknown color specifier:false File "B:\Comfyul-aki-vllexecution,py", line 152, in recursive executeutput data, output ui = get output data(obi, input data all)File“B:\ComfyuI-aki-vllexecution,py", line 82, in get_output_data"eturn values = map node over list(obj, input data all, obi.FUNCTION, allow interrupt=True)File"B:iComfvlI-aki-vllexecution.py ,line 75,in map node over listresults.append(getattr(obj, func)(**slice dict(input data all, i)))File "B:\ComfyuI-aki-v1\custom nodes\comfyui-mixlab-nodes nodes ImageNode.py", line 1611, in runimg, mask=generate text image(text, font path, font size, text color, vertical,stroke, (0, 0, 0),1,spacing,line spacing, paddingFile "B: ComfyuI-aki-v1(custom nodes comfyui-mixlab-nodes (nodes ImageNode.py", line 1023, in generate text_imagelraw.text((x,y),char, font=font, fill=text_color)File "B:\ComfyuI-aki-v1\pythonlliblsite packages\PILlImageDraw.py", line 682, in textgetink(fi11)ink =File"B:lComfyuI-aki-v1lpythonlliblsite packageslPILlImageDraw.py",line 619, in getinkink,fill ink = self._getink(fill)"B:lConfyuI-aki-vllpythonlliblsite packageslPILlImageDraw.py.Fileline 161,in getinkink ImageColor.getcolor(ink,self.mode)File"B:\ComfyuI-aki-v1lpythonlliblsite packages PILlImageColor.py"line 144,in getcoloralpha=getrgb(color),255rgb,File"B:\ComfyuI-aki-v1\pythonlliblsite packages\PILlImageColor.py", line 125, in getrgbraise ValueError(msg) 求问应该怎么解决呢

godischense commented 1 day ago

遇到这个问题的朋友可以去这里寻找完美解决方法:https://www.bilibili.com/opus/961012319932907520

弄了,但是节点直接加载不出来了

godischense commented 1 day ago

感谢反馈,我会抽空研究下如何解决

作者,这个问题修复了吗?

BannyLon commented 13 hours ago

遇到这个问题的朋友可以去这里寻找完美解决方法:https://www.bilibili.com/opus/961012319932907520

弄了,但是节点直接加载不出来了

仔细核对下,是不是代码更改的问题。如果按照我的修改是没问题,好多人都修改成功。我猜你是修改代码哪里写的不规范。