Skip to main content

Perfect Bangla/Bengali text rendering on images/video with correct vowel positioning and joint letter

Project description

Bangla Text Renderer

Perfect Bangla/Bengali text rendering on images with correct vowel positioning and joint letter handling.

Problem

When using PIL/Pillow to render Bangla text on images, vowel marks (কার) like ি, ে, ৈ often appear in the wrong position - one letter behind where they should be. This package fixes that issue.

Installation

pip install bangla-text-renderer

Quick Start

from bangla_text_renderer import BanglaTextRenderer
from PIL import Image

# Create renderer with your Bangla font
renderer = BanglaTextRenderer(
    font_path='NotoSansBengali-Bold.ttf', # give your font name here /// download your font .ttf file and put on windows\fonts directory
    font_size=48,
    color=(255, 255, 255, 255)  # White
)

# Render text
text = "বাংলা লেখা সঠিকভাবে"
img = renderer.render_text(text, width=800)

# Save image
img.save('output.png')

Features

  • Perfect vowel positioning - Fixes misplaced vowel marks (ি, ী, ে, ৈ, etc.)
  • Joint letter support - Handles যুক্তাক্ষর correctly
  • Text wrapping - Automatic word wrapping
  • Multiple alignments - Left, center, right
  • Shadow effects - Built-in text shadow
  • Unicode normalization - Proper NFC normalization

Advanced Usage

Text with Shadow

img = renderer.render_text_with_shadow(
    text="বাংলা টেক্সট",
    width=800,
    shadow_offset=3,
    shadow_color=(0, 0, 0, 180)
)

Custom Alignment and Line Spacing

img = renderer.render_text(
    text="বাংলা লেখা",
    width=800,
    max_lines=3,
    line_spacing=15,
    align='center',  # 'left', 'center', or 'right'
    background=(255, 255, 255, 255)  # White background
)

Integration with Existing Images

from PIL import Image

# Load base image
base_img = Image.open('background.jpg').convert('RGBA')

# Render Bangla text
text_img = renderer.render_text("বাংলা", width=500)

# Paste text on base image
base_img.paste(text_img, (100, 100), text_img)
base_img.save('result.png')

How It Works

The package implements proper Bangla text shaping by:

  1. Normalizing text to Unicode NFC form
  2. Splitting combined vowel signs (ো, ৌ)
  3. Reordering pre-base vowels to appear before consonants
  4. Processing joint letters (যুক্তাক্ষর) with virama (্)

This ensures text renders exactly as it should appear visually.

Supported Fonts

Works with any Unicode Bangla font:

  • Noto Sans Bengali
  • Noto Serif Bengali
  • Kalpurush
  • SolaimanLipi
  • Vrinda
  • And more...

Requirements

  • Python 3.7+
  • Pillow 8.0.0+

License

MIT License

Contributing

Contributions welcome! Please feel free to submit a Pull Request.

Support

If you encounter any issues, please open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bangla_text_renderer-1.4.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bangla_text_renderer-1.4.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file bangla_text_renderer-1.4.0.tar.gz.

File metadata

  • Download URL: bangla_text_renderer-1.4.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.14.0

File hashes

Hashes for bangla_text_renderer-1.4.0.tar.gz
Algorithm Hash digest
SHA256 13f0e3b79f92f6affb0eaf98b3939b2356b901b9bbcd7ee33151bc8deb5eb02a
MD5 2ed8c8449f97367c62ae94868fb1f8e3
BLAKE2b-256 40a3e4bb71048fb18294f006d2a35dd354099b70cdc64c4e77e99427c7e631c3

See more details on using hashes here.

File details

Details for the file bangla_text_renderer-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bangla_text_renderer-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b832b48f8125d40af5f51cd40243aab6d84d769adeb2aceb1b4cf670e2e5f83c
MD5 9834dbd8cac43ad3dc67e6222a99dbbb
BLAKE2b-256 a87d4d953292747ea4c59b5918b970a6756c13e12d8fb3c1b16eccd58c62bbcf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page