Training process automation

January 25, 2009 at 11:34 am (Uncategorized)

I am so excited.

#-*- coding:utf8 -*-
fromPILimport Image

im ="RGB",(400,400))

draw = ImageDraw.Draw(im)

# use a truetype font
font= ImageFont.truetype("/usr/share/fonts/truetype/ttf-bengali-fonts/lohit_bn.ttf",50)

txt2=" ি"

draw.text((10, 10), unicode(txt,'UTF-8'), font=font)


That means the *entire* training+testing process can be automated 🙂 🙂 🙂

Damn, I dint even have to go to ISI. Ofcourse, going to ISI was quite an experience in itself, but more on that later.



  1. Sayamindu said,

    I’m not sure if this falls inside the scope of what you are trying to achieve, but the code won’t work for stuff like, for example:

    txt4=” ি”

    The following code takes care of the shaping automatically:

    #-*- coding:utf8 -*-

    import cairo
    import pango
    import pangocairo

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 600, 100)
    context = cairo.Context(surface)

    pc = pangocairo.CairoContext(context)

    layout = pc.create_layout()
    layout.set_font_description(pango.FontDescription(‘Lohit Bengali Bold 14’))
    layout.set_text(‘অন্ধকারে চৌরাশীটা নরকের কুন্ড, তাহাতে ডুবায়ে ধরে পাতকীর মুন্ড’)

    # Next four lines take care of centering the text. Feel free to ignore 😉
    width, height = surface.get_width(), surface.get_height()
    w, h = layout.get_pixel_size()
    position = (width/2.0 – w/2.0, height/2.0 – h/2.0)



  2. Sayamindu said,

    ..and in the above example, you can take care of stuff like kerning, linespacing, etc as well.
    The pango manual has all the gory details.

  3. Sayamindu said,

    (and with cairo, you can simulate rotated text, skewing, etc as well)

  4. indu said,

    And getting LayoutIterator object and pango.LayoutIter.get_char_extents for each characters of text. will it solve the problem of getting bounding boxes of characters

  5. santhosh thottingal said,

    pango-view -q -w 600 –align=left –justify –margin=100 –font=Rachana -o output.png inputfile.txt


    pango-view -q -w 600 –align=left –justify –margin=100 –font=Rachana -o output.pdf inputfile.txt

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: