Image-To-ASCII icon indicating copy to clipboard operation
Image-To-ASCII copied to clipboard

OSError: cannot open resource

Open kasai2210 opened this issue 4 years ago • 4 comments

Traceback (most recent call last): File "main.py", line 144, in to_ascii(argv[1]) File "main.py", line 110, in to_ascii create_char_map(33, 750) File "main.py", line 53, in create_char_map load_characters(start_index, end_index) File "main.py", line 61, in load_characters char_img = char_image(chr(i)) File "main.py", line 20, in char_image font = ImageFont.truetype("Monaco", 40) File "C:\Python38\lib\site-packages\PIL\ImageFont.py", line 642, in truetype return freetype(font) File "C:\Python38\lib\site-packages\PIL\ImageFont.py", line 639, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "C:\Python38\lib\site-packages\PIL\ImageFont.py", line 187, in init self.font = core.getfont( OSError: cannot open resource

kasai2210 avatar Jan 31 '21 17:01 kasai2210

I got this error as well: python main.py sample/gold_face.jpg 2 Traceback (most recent call last): File "/home/ubuntu/environment/Image-To-ASCII/main.py", line 144, in to_ascii(argv[1]) File "/home/ubuntu/environment/Image-To-ASCII/main.py", line 110, in to_ascii create_char_map(33, 750) File "/home/ubuntu/environment/Image-To-ASCII/main.py", line 53, in create_char_map load_characters(start_index, end_index) File "/home/ubuntu/environment/Image-To-ASCII/main.py", line 61, in load_characters char_img = char_image(chr(i)) File "/home/ubuntu/environment/Image-To-ASCII/main.py", line 20, in char_image font = ImageFont.truetype("Monaco", 40) File "/usr/local/lib/python3.9/site-packages/PIL/ImageFont.py", line 852, in truetype return freetype(font) File "/usr/local/lib/python3.9/site-packages/PIL/ImageFont.py", line 849, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/usr/local/lib/python3.9/site-packages/PIL/ImageFont.py", line 209, in init self.font = core.getfont( OSError: cannot open resource

ssocolow avatar Mar 02 '21 14:03 ssocolow

Please help me. I got same issue.

Traceback (most recent call last): File "img_to_ascii.py", line 144, in to_ascii(argv[1]) File "img_to_ascii.py", line 110, in to_ascii create_char_map(33, 750) File "img_to_ascii.py", line 53, in create_char_map load_characters(start_index, end_index) File "img_to_ascii.py", line 61, in load_characters char_img = char_image(chr(i)) File "img_to_ascii.py", line 20, in char_image font = ImageFont.truetype("Monaco", 40) File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 642, in truetype return freetype(font) File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 639, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/usr/lib/python3/dist-packages/PIL/ImageFont.py", line 187, in init self.font = core.getfont( OSError: cannot open resource

A-Little-Hat avatar Apr 26 '21 07:04 A-Little-Hat

I got the same error as you guys. Did anyone fix it?

DastanDev avatar May 25 '21 17:05 DastanDev

Still same issue. I tried changing the font loaded from Monaco to Consolas as I didn't have Monaco installed But something has changed in the last 6 years to the pillow lib and the dev didn't include a requirements.txt so we don't know the exact ver of the lib the dev used. On windows at least, you can ghetto fix this by pointing the truetype font loader to an absolute file path.

def char_image(char):
    # Get an image with a char drawn on it.
    # font = ImageFont.truetype("Monaco", 40)
    font = ImageFont.truetype("C:/Windows/Fonts/consolab.ttf", 40)

And now it does output stuff to the console at least. But again on windows when trying to save this to a file. python main.py image.jpg 2 > image.txt We get a new error of cant encode char '\u01cb'. So something is now messed up in the 'charmap' Unicode to ascii generator...?

MobCat avatar Feb 03 '23 22:02 MobCat