Hi to all. I am developing with Inky pHAT and I need to display an icon. I would like to use font-font-awesome package from Piromoni, but I can’t find any example how to get the right icont from the font. Someone could help please?
I don’t understand this much so there is likely to be a better way to do this. The method I’ve got is an odd blend of using the
FontAwesome python package and the
FontAwesome5-Free.otf file present in Pimoroni’s
Start by installing the FontAwesome package for Python:
pip3 install fontawesome
Then, you need to install the FontAwesome font. If you need to, download the
python-fonts package from Pimoroni’s Git repo:
git clone https://github.com/pimoroni/fonts-python.git
FontAwesome5-Free.otf from Pimoroni’s repo into
/usr/share/fonts. This essentially “installs” the font so that Python knows where to find it.
Now you can use the FontAwesome symbols to write to images:
# Set up the Inky board as appropriate, in this case an Inky Impression. from inky.inky_uc8159 import Inky # Initialise the Inky board inky = Inky() # Import the Python PIL modules for drawing the image with the symbols from PIL import Image, ImageFont, ImageDraw # Import the FontAwesome Python package import fontawesome as fa # Create a font using the FontAwesome font file from Pimoroni font = ImageFont.truetype("FontAwesome5-Free.otf", 40) # Create a blank 600x448 pixel image to draw on, in white/ (255,255,255) img = Image.new("RGB", (600, 448), (255,255,255)) # Convert the blank image to an ImageDraw object so it can be manipulated drawnImage = ImageDraw.Draw(img) # Draw an icon onto it as if it were text, in this case a paper plane, in black drawnImage.text((30, 30), fa.icons["paper-plane"], font=font, fill=(0,0,0)) # Tell inky to use the image as the thing to be displayed inky.set_image(img) # Display the image inky.show()
To choose a symbol check the list of symbols at the FontAwesome website. I’m not absolutely certain about this, but if you tick the “Free” and “Regular” filters on the left I think all of the remaining symbols will work. You just need to replace
"paper-plane" in the
#Draw an icon line to the name of the symbol you want to use.
EDIT: It seems that some of the Free and Solid symbols work too, but not all. This may take some trial and error.
EDIT2: Derp. The Pimoroni fonts folder has three types of FontAwesome: Free, Free-Solid and Brands. You should be able to get the corresponding symbols by importing those instread of just Free.