0

I am trying to render Bengali fonts correctly in blender, but it is not rendering properly. I faced the same problem trying to draw Bengali text on image with python. I found that pillow is able to do this, but it was not straightforward like English text. I was able to get it working following these two links below,

How do I install 'libraqm' library in Google Colab?

How to install pre-built Pillow wheel with libraqm DLLs on Windows?

These are the results without and with libraqm,

Incorrect

enter image description here

Correct

enter image description here

This is the basic code,

from PIL import ImageFont, ImageDraw, Image
import numpy as np
import matplotlib.pyplot as plt

image = np.zeros((200, 600, 3), np.uint8)
image = Image.fromarray(np.uint8(image * 255))

draw = ImageDraw.Draw(image)

# use a truetype font
font = ImageFont.truetype("/content/BalooDa2-Medium.ttf", 24)

draw.text((20, 25), "আমাদের দেশের ক্রিকেটাররা এখন টেস্ট খেলায় জিততে জানে", font=font)
draw.text((20, 50), "গরমে সুস্থ থাকুন", font=font)

plt.figure(figsize = (20,20))
plt.imshow(image)

Full script is here, https://github.com/quickgrid/CodeLab/blob/master/colab/Pillow_Render_Bangla_Font_Text_to_Image_libraqm.ipynb.

Using custom Bengali font in blender produces incorrect result like this

enter image description here

I am wondering how to achieve the same thing as libraqm in blender with text. Any way to install libraqm with pillow to render font properly in blender or any other ways?

B200011011
  • 3,798
  • 22
  • 33

1 Answers1

0

Edit:

Turns out Blender 2.92 already has path tracing included. Drag and dropping image in viewport, then Object > Trace Image to Grease Pencil on selected object is able trace the path which can extruded to any height requirement to generate 3D text.

Though there are some visible problem in output trace as shown below.

enter image description here

Source, https://www.youtube.com/watch?v=m5QdBZ5sDG0


Black and white image can be traced with bitmap tracer to convert to svg path. Inkscape is able to do this and it can be exported blender. I found a temporary way around this.

I would still prefer an answer that removes the black pixels (or inverted) and extrudes the white pixels along Z axis to given height to create mesh using python without something like Inkscape. To this end my idea at the moment is using python get the contours, somehow save these as vector path, save as svg and finally load in blender.

Found this non ML based paper on bitmap tracing, http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.159.5801&rep=rep1&type=pdf.

I found two more ways to render font with height, but it is not my preferred way. One is using bump and another is using displacement + bump. Using bump does not give proper height, but looks good from far and able get the correct shadows.

To use displacement + bump or just displacement the plane needs to be subdivided a lot to get proper height with somewhat good results using blender cycles. The black and white mask image should be used as image texture with cubic interpolation to improve the results.

enter image description here

B200011011
  • 3,798
  • 22
  • 33