#!/usr/bin/python3 #-*- coding:utf8 -*- # Modified for python3 # python2 version https://gist.github.com/santhoshtr/bea3da00651bcd18e282 import cairo from gi.repository import Gtk, Gdk, Pango, PangoCairo import cairo surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 600, 100) context = cairo.Context(surface) pc = PangoCairo.create_context(context) layout = PangoCairo.create_layout(context) layout.set_font_description(Pango.FontDescription('Serif Normal 12')) layout.set_text('മലയാളം हिन्दी ଓଡ଼ିଆ தமிழ்', -1); # Next four lines take care of centering the text. Feel free to ignore ;-) width, height = surface.get_width(), surface.get_height() print(width, height) w, h = layout.get_pixel_size() position = (width/2.0 - w/2.0, height/2.0 - h/2.0) position = (w,h) context.move_to(*position) PangoCairo.show_layout(context, layout) surface.write_to_png('malayalam.png')