librelist archives

« back to archive

Methods to create text preview from a font(.ttf).

Methods to create text preview from a font(.ttf).

From:
Ign Aarushi
Date:
2012-07-01 @ 14:18
Hi,

i was just experimenting with the PIL module of the Python library. I was
genertaing Images from a font file. To preview the text by a particular
font and then make it into a image.

My code:

#!/usr/local/bin/python

from PIL import Image, ImageDraw, ImageFont

fontPath = "Dearest.ttf"

font1  =  ImageFont.truetype ( fontPath,50 )

im  =  Image.new ( "RGB", (1000,100), "white" )

draw  =  ImageDraw.Draw ( im )

draw.text ( (0,0), "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSs", font=font1,
fill="black" )

im.save ( "test.jpg" )

It does work great by the way. But there is a little problem i am
experiencing about the letters drawn in the image.

They are not fully shown. I tried attaching the pics but i am not able to.
i recieve a error message that the message is too big. so i uploaded the
pics to my google account.

link :

https://plus.google.com/photos/101519536336237573474/albums/5760204205625934209?authkey=CN-mupupwaOl8gE

image1 is the generated image by this script and image 2 is the one i want.
In the image1 the letters are cutted from the top. I don't know how to show
them full.

I have tried many scripts but i am not able to do it. So what improvement
do i need to make in the script or what more should i add in it to generate
and show the letters properly.

Thank you very much.

Re: [flask] Methods to create text preview from a font(.ttf).

From:
Jesaja Everling
Date:
2012-07-01 @ 14:49
Hi,

did you try setting the position of the text a little bit further down?
Like this:

draw.text( (0,25), "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSs",
font=font1, fill="black" )

By the way, I really would use PNG for this. JPEG is really not suited
that well for compressing lines and hard edges, it's optimized for
compressing natural images.

Best Regards,

Jesaja Everling


On Sun, Jul 1, 2012 at 4:18 PM, Ign Aarushi <ign.aarushi@gmail.com> wrote:
> Hi,
>
> i was just experimenting with the PIL module of the Python library. I was
> genertaing Images from a font file. To preview the text by a particular font
> and then make it into a image.
>
> My code:
>
> #!/usr/local/bin/python
>
> from PIL import Image, ImageDraw, ImageFont
>
> fontPath = "Dearest.ttf"
>
> font1  =  ImageFont.truetype ( fontPath,50 )
>
> im  =  Image.new ( "RGB", (1000,100), "white" )
>
> draw  =  ImageDraw.Draw ( im )
>
> draw.text ( (0,0), "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSs", font=font1,
> fill="black" )
>
> im.save ( "test.jpg" )
>
> It does work great by the way. But there is a little problem i am
> experiencing about the letters drawn in the image.
>
> They are not fully shown. I tried attaching the pics but i am not able to. i
> recieve a error message that the message is too big. so i uploaded the pics
> to my google account.
>
> link :
> 
https://plus.google.com/photos/101519536336237573474/albums/5760204205625934209?authkey=CN-mupupwaOl8gE
>
> image1 is the generated image by this script and image 2 is the one i want.
> In the image1 the letters are cutted from the top. I don't know how to show
> them full.
>
> I have tried many scripts but i am not able to do it. So what improvement do
> i need to make in the script or what more should i add in it to generate and
> show the letters properly.
>
> Thank you very much.

Re: [flask] Methods to create text preview from a font(.ttf).

From:
Ign Aarushi
Date:
2012-07-01 @ 14:58
Thank you for your reply,  Jesaja Everling
Yeah I tried that. (0,25) It just moves the line lower and display the
letters same.
The clipping is still not removed and yes thanks for that advice to use PNG
rather than JPEG.
Please Help.

Re: [flask] Methods to create text preview from a font(.ttf).

From:
Jesaja Everling
Date:
2012-07-01 @ 16:22
It works fine for me, but the font is also rendered much smaller on my
system, even if i'm using 50 as font size.
Maybe this question on stackoverflow helps:
http://stackoverflow.com/questions/1933766/fonts-clipping-with-pil

Best regards,

Jesaja Everling
 On Jul 1, 2012 4:59 PM, "Ign Aarushi" <ign.aarushi@gmail.com> wrote:

> Thank you for your reply,  Jesaja Everling
> Yeah I tried that. (0,25) It just moves the line lower and display the
> letters same.
> The clipping is still not removed and yes thanks for that advice to use
> PNG rather than JPEG.
> Please Help.
>

Re: [flask] Methods to create text preview from a font(.ttf).

From:
Ign Aarushi
Date:
2012-07-01 @ 16:44
that script worked great for me before too. but i don't know what's
happening now. In the link like you showed the letters are cut-off from the
bottom. mine are cut-off from the top. I don't know the reason for it and
neither any of the examples i use are helping to create unclipped letters.
thank you so much for your time.
and someone please help if you know anything about it.

Re: [flask] Methods to create text preview from a font(.ttf).

From:
Smartboy
Date:
2012-07-01 @ 18:42
If you can't get PIL to work, then you could always use ImageMagick.
http://www.imagemagick.org/script/api.php

Smartboy

On Sun, Jul 1, 2012 at 9:44 AM, Ign Aarushi <ign.aarushi@gmail.com> wrote:

> that script worked great for me before too. but i don't know what's
> happening now. In the link like you showed the letters are cut-off from the
> bottom. mine are cut-off from the top. I don't know the reason for it and
> neither any of the examples i use are helping to create unclipped letters.
> thank you so much for your time.
> and someone please help if you know anything about it.
>