[Image-SIG] Using PIL to merge postscript generated text and png files

Laura & Edward Cannon cannon.el at gmail.com
Thu Mar 5 17:00:05 CET 2009


As far as I know, line wrapping in PIL has to be done automatically.
You need to use the font.getsize(text) method in ImageFont it returns
a (width, height) tuple for the given text. A little work will allow
you to write a function to split the lines at the appropriate places
(I would split the text into words with the .split() string method)
and then you can draw each line individually.
Edward

On 3/5/09, Chris Adams <chris at stemcel.co.uk> wrote:
> Hi Edward, thanks for the heads up!
>
>  In the end, I used FontForge to create a Truetype font from the postscript,
> and it worked pretty seamlessly - it's not quite photoshop, but it IS free
> and cross platform (http://fontforge.sourceforge.net/)
>
>  Initially, the typefaces looked nasty and pixellated when I was using an
> initial png8 graphic -
>   instead of a full colour version.
>
>  I resolved this  case by exporting the file from photoshop as a 24bit png
> instead, which took the rough edges off the fonts.
>
>  However, I'm still stuck with the issue of having no line wrapping.
>
>  Is this something PIL can handle as well?
>
>  C
>
>
>  On 4 Mar 2009, at 16:26, Laura & Edward Cannon wrote:
>
>
> > My best suggestion is to convert the font you need to a format that
> > PIL can understand, either its own bitmap format or to a truetype
> > font. Font conversion utilities exist, and you would only need to do
> > the conversion once, and then just use the converted font. It may not
> > be completely elegant, but it is probably the minimum amount of work.
> > Edward
> >
> > On Wed, Mar 4, 2009 at 5:06 AM, Chris Adams <chris at stemcel.co.uk> wrote:
> >
> > > Hi there,
> > >
> > > I'm trying to programatically generate text onto an existing png file as
> > > part of a very simple online tool for an NGO, and I'm looking at using
> PIL
> > > to do this.
> > >
> > > Blank badge:
> > >
> http://test.stemcel.co.uk/clients/org/org-widget/blank_badge/
> > >
> > > The copy  would be pasted in goes here:
> > >
> http://test.stemcel.co.uk/clients/org/org-widget/blank_badge/posted_copy_badge.png
> > >
> > > And the rollover state would be generated as well here:
> > >
> http://test.stemcel.co.uk/clients/org/org-widget/blank_badge/posted_copy_badge_rollover.png
> > >
> > > However, the issue here is that I'm trying to do this with a Postscript
> font
> > > (not a Truetype .ttf one), which needs the PSDraw class, rather than the
> > > basic ImageFont class, and I was under the impression that it was
> designed
> > > for printing rather than output for the screen.
> > >
> > > I'm used to using GUI apps for design related work like this or writing
> html
> > > and css on the front end of websites, and I'm very new to python, but I
> > > naively assumed that doing this would be simple, and it's proving not to
> be
> > > the case so far.
> > >
> > > What's the best way to try doing what I'm doing?
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > ---
> > > I'm currently only checking my email at 9am, midday and at 4pm.
> > > If you need a response from me urgently, please call or text my mobile,
> or
> > > contact me via Skype (chris.d.adams).
> > > ---
> > > Chris Adams
> > > Stemcel Studios
> > > The Hub
> > > 5 Torrens Street
> > > London
> > > EC1V 1NQ
> > >
> > > email: chris at stemcel.co.uk
> > > web:  www.stemcel.co.uk
> > > twitter:chris_d_adams
> > > skype: chris.d.adams
> > > mob: 07974 368 229
> > > tel: 0207 558 8971
> > >
> > > _______________________________________________
> > > Image-SIG maillist  -  Image-SIG at python.org
> > > http://mail.python.org/mailman/listinfo/image-sig
> > >
> > >
> > _______________________________________________
> > Image-SIG maillist  -  Image-SIG at python.org
> > http://mail.python.org/mailman/listinfo/image-sig
> >
>
>  --
>  ---
>  I'm currently only checking my email at 9am, midday and at 4pm.
>  If you need a response from me urgently, please call or text my mobile, or
> contact me via Skype (chris.d.adams).
>  ---
>  Chris Adams
>  Stemcel Studios
>  The Hub
>  5 Torrens Street
>  London
>  EC1V 1NQ
>
>  email: chris at stemcel.co.uk
>  web:  www.stemcel.co.uk
>  twitter:chris_d_adams
>  skype: chris.d.adams
>  mob: 07974 368 229
>  tel: 0207 558 8971
>
>


More information about the Image-SIG mailing list