PDA

View Full Version : Python, how to get font path?



denham2010
July 29th, 2008, 08:04 AM
Hi,

I am trying to do some image manipulation in Python by adding text to existing images.

I am using the imported modules Image, ImageDraw and ImageFont.

Now adding the text to the image is the easy part. The problem I am having is I need to allow the user to select a font, using the gtk.FontSelectionDialog widget. With this, I am able to get the name of the selected font, but not the path to the selected font's .ttf file.

To set the font using ImageFont, I need the path to the .ttf font file.

I have searched for hours on google and a variety of forums, but have not been able to find a solution.

Hoping someone can help me to work out how to get the selected font's path (from a gtk.FontSelectionDialog) in python so I can pass it to ImageFont.

Thanks for your assistance.

denham2010
July 31st, 2008, 10:43 AM
Sorry, BUMP...

Hoping someone has a solution.

Thanks.

Cecilio
October 15th, 2008, 06:22 PM
I have the same problem. Today I was googling to try to find an answer and found your post. Did you get a solution?

Thanks
Cecilio

unutbu
October 15th, 2008, 08:45 PM
Perhaps this helps?

http://www.pygtk.org/pygtk2tutorial/examples/calendar.py
Check out the
calendar_select_font method. When the ok button is clicked, the calendar_font_selection_ok method is called, and the font is set with


self.font = self.font_dialog.get_font_name()
if self.window:
font_desc = pango.FontDescription(self.font)
if font_desc:
self.window.modify_font(font_desc)

The code comes from this pygtk tutorial:
http://www.pygtk.org/pygtk2tutorial/sec-FontSelectionDialog.html

Cecilio
October 16th, 2008, 02:32 PM
Thank you very much for the information. It is a great help!

Best reagards,
Cecilio

JuanC
December 5th, 2008, 06:14 PM
Now i get pango.FontDescription(font_name) , how to use ImageFont from PIL to load this font?

unutbu
December 5th, 2008, 06:27 PM
http://ubuntu-virginia.ubuntuforums.org/showthread.php?t=995195

JuanC
December 5th, 2008, 10:30 PM
How to get font path from pango.FontDescription to use with ImageFont.truetype or ImageFont.load?