[PyKDE] QFont and PIL

Andreas Pakulat apaku at gmx.de
Wed Jul 19 17:59:07 BST 2006


On 19.07.06 18:24:52, Aljosa Mohorovic wrote:
> i use QFontDialog to get QFont data so i can use some font (available
> from system) later to write text on image using PIL but i can't find
> method which returns system filename for selected font.
> 
> i'm using Qt4 v.4.1.4 / PyQt v.4.0.1 / PIL 1.1.5 / Python 2.4.2
> 
> code:
> >>>
> font = ImageFont.truetype(str(self.font_filename)+".ttf", self.font_size)
> draw = ImageDraw.Draw(img)
> draw.text((10, 10), self.text, font=font,fill=self.color.getRgb())
> <<<
> 
> i'm looking for something like QFont.getFilename() or a way to use
> selected QFont from PIL.

For the first one, you won't get a filename, because Qt itself doesn't
know the name of the file used. All it knows is an "abstract" font name
as provided by fontconfig under Linux and I guess similar
font-file-abstraction systems under Windows and MacOS.

You can't use the 2nd method either I think, at least not if PIL really
renders the font itself. If it can use fontconfig under linux (or the
"other font systems on the other OS") then you should be fine by
fetching the same font name, family, size and so on from the font
system.

Also : Why do you need PIL? Qt can itself draw to images and then put
these into files, into bytearrays to send of the the network or anything
else you can do with an encoded image. So if you need PIL (I don't know
PIL other than that it's an imaging lib) to do some fancy image
processing, you could first paint everything you want into a QImage and
then save it into a temporary file (or in-memory file) and read it from
there into PIL.

Andreas

-- 
You teach best what you most need to learn.




More information about the PyQt mailing list