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
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
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
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...?