[Chennaipy] Tamil Fonts Exception

Vijay Kumar B vijaykumar at zilogic.com
Thu Sep 30 04:20:25 EDT 2021


---- On Thu, 30 Sep 2021 12:07:23 +0530 Abirami Moorthy <mailto:mabirami8799 at gmail.com> wrote ----



I have a sample certificate. I would like to write names in tamil on certificate using python-pillow



here the program link

https://github.com/Abirami8799/python-project/blob/master/certificate.py

output showing like this

https://pasteboard.co/YDSNp6tADZIt.png



I used some fonts like Noto Sans Tamil Regular, Sundaram-3811,TSCu_Paranar,TSCu_saiIndira,Latha, Nirmala- but could not get the correct output.








Hi Abirami,

You need to use a text layout engine like Pango, for rendering the text correctly. See https://pangocairocffi.readthedocs.io/en/latest/index.html


The example adapted from the pangocairocffi tutorial is provided below. 



import cairocffi

import pangocffi

import pangocairocffi



# Create the surface and get the context

filename = 'test.png'

surface = cairocffi.ImageSurface.create_from_png(filename)

context = cairocffi.Context(surface)



context.translate(20, 20)



# Build the layout

layout = pangocairocffi.create_layout(context)

layout.set_markup('<span font="30">தேன்மொழி</span>')



# Render the layout

pangocairocffi.show_layout(context, layout)



# Output the surface

surface.write_to_png(filename)

surface.finish()


Regards,

Vijay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/chennaipy/attachments/20210930/8445b1c8/attachment.html>


More information about the Chennaipy mailing list