csgoh / processpiper

An open source python library to generate business process diagram using code or plain text.
https://github.com/csgoh/processpiper
MIT License
148 stars 10 forks source link

OSError: cannot open resource #52

Open marconimedeiros2 opened 1 week ago

marconimedeiros2 commented 1 week ago

Im trying to render a SVG file in a headless service (Google Cloud Functions) but this error is showing up when I try to use "render" function:

OSError: cannot open resource

This is a problem with PIL lib.

Anyone can help me with this problem?

csgoh commented 6 days ago

Can you share your code and the full error stack trace? When logging an issue, please provide as much information as possible to help us troubleshoot the problem.

marconimedeiros2 commented 6 days ago

Code:

from processpiper.text2diagram import render

input_syntax = """
title: Sample Test Process
colourtheme: BLUEMOUNTAIN
    lane: End User
        (start) as start
        [Enter Keyword] as enter_keyword
        (end) as end
pool: System Search
    lane: Database System
        [Login] as login
        [Search Records] as search_records
        <Result Found?> as result_found
        [Display Result] as display_result
        [Logout] as logout
    lane: Log System
        [Log Error] as log_error

start->login: User \\nAuthenticate
login->enter_keyword: Authenticated
enter_keyword->search_records: Search Criteria
search_records->result_found: Result
result_found->display_result: Yes
display_result->logout->end
result_found->log_error: No
log_error->display_result

footer: Generated by ProcessPiper
"""

render(input_syntax, "my_process_map.png")

Output error:

File "/workspace/main.py" 
render(input_syntax, "my_process_map.svg") 

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/processpiper/text2diagram.py", line 367, in render 
exec(generated_code) 

File "<string>", line 27, in <module> 

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/processpiper/processmap.py", line 461, in draw 
self._set_draw_position() 

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/processpiper/processmap.py", line 297, in _set_draw_position 
self._title.set_draw_position( 

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/processpiper/title.py", line 47, in set_draw_position 
self.width, self.height = painter.get_text_dimension( 
                                        ^^^^^^^^^^^^^^^^^^ 

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/processpiper/painter.py", line 1358, in get_text_dimension _, _, font_width, font_height = self.get_char_width( 

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/processpiper/painter.py", line 378, in get_char_width 
font = ImageFont.truetype(self.get_font_path(text_font), size=text_font_size) 
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/PIL/ImageFont.py", line 807, in truetype 
return freetype(font) 
           ^^^^^^^^

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/PIL/ImageFont.py", line 804, in freetype 
return FreeTypeFont(font, size, index, encoding, layout_engine) 
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/layers/google.python.pip/pip/lib/python3.12/site-packages/PIL/ImageFont.py", line 244, in __init__ 
self.font = core.getfont( 
                 ^^^^^^^^

Function execution took 110 ms, finished with status: 'crash' 
OSError: cannot open resource 
csgoh commented 5 days ago

It looks like the package cannot find the font file. See this page Installation for additional steps to install font for Ubuntu or Linux.