VickiLanger / LGBTQ-of-the-day-bot

Twitter bot tweeting fun goofy lgbtq things and queer history of the day
https://twitter.com/LGBTQotd
GNU General Public License v3.0
82 stars 173 forks source link

Change image text from default to a real font #104

Closed VickiLanger closed 3 years ago

VickiLanger commented 3 years ago

Describe the bug Posting of images was an added feature with #90 & #94. The image post great, but there are issues with the text. In get_img_for_tweet.py, the font is currently set to ImageFont.load_default() but it needs to use a file from the assets folder.

Expected behavior Use font from file from the assets folder.

Should be able to do this, but Heroku is throwing errors. Not sure if my path isn't right or if it's something with Heroku

font_type = ImageFont.truetype('/assets/Nunito-Regular.ttf', 40)
font_type2 = ImageFont.truetype('/assets/Nunito-Regular.ttf', 40*2)
2020-10-16T12:00:22.737878+00:00 app[scheduler.1478]:     font_type = ImageFont.truetype('/assets/Nunito-Regular.ttf', 40)
2020-10-16T12:00:22.737901+00:00 app[scheduler.1478]:   File "/app/.heroku/python/lib/python3.6/site-packages/PIL/ImageFont.py", line 836, in truetype
2020-10-16T12:00:22.738235+00:00 app[scheduler.1478]:     return freetype(font)
2020-10-16T12:00:22.738236+00:00 app[scheduler.1478]:   File "/app/.heroku/python/lib/python3.6/site-packages/PIL/ImageFont.py", line 833, in freetype
2020-10-16T12:00:22.738581+00:00 app[scheduler.1478]:     return FreeTypeFont(font, size, index, encoding, layout_engine)
2020-10-16T12:00:22.738582+00:00 app[scheduler.1478]:   File "/app/.heroku/python/lib/python3.6/site-packages/PIL/ImageFont.py", line 194, in __init__
2020-10-16T12:00:22.738752+00:00 app[scheduler.1478]:     font, size, index, encoding, layout_engine=layout_engine
2020-10-16T12:00:22.738756+00:00 app[scheduler.1478]: OSError: cannot open resource

Screenshots If applicable, add screenshots to help explain your problem. screenshot of the image post with super tiny ugly default python pillow font


Don't forget to follow the bot on Twitter to see the hard work you put in.

JasirZaeem commented 3 years ago

Can you share the directory structure for you heroku app when its deployed? I'm guessing '/assets/Nunito-Regular.ttf' is not the location of the font on so that is why it can't find the resource.

VickiLanger commented 3 years ago

That would make sense. I'm not sure how to find the directory structure in Heroku. I have it automatically deploy from the production branch. So, I assumed it was just using what I gave it.

JasirZaeem commented 3 years ago

I tried it on my computer, ImageFont.truetype('/assets/Nunito-Regular.ttf', 40) did not work, but ImageFont.truetype('assets/Nunito-Regular.ttf', 40) did work (removed the beginning slash), so this might work. Another thing that worked was having the complete path ImageFont.truetype('C:/users...../Nunito-Regular.ttf', 40). One of these might work on heroku, if the first does not fix it this question would help you see the file structure, and you can see directories/files and see the full path that way.

VickiLanger commented 3 years ago

I should've tested that. I really thought it was going to want that beginning slash. The font now works.

JasirZaeem commented 3 years ago

Glad it is working now! I suppose this issue can be closed then.