Skip to content

Instantly share code, notes, and snippets.

View andjc's full-sized avatar

Andj andjc

  • Melbourne, Australia
View GitHub Profile
#!/usr/bin/env python3
import shlex
import subprocess
import uharfbuzz as hb
font_dir = 'fonts/g/mac/10.15.7/'
font_path = f'{font_dir}Hiragino Kaku Gothic W4.ttc'
font_path = f'{font_dir}Hiragino MaruGothic ProN W4.ttc'
font_path = f'{font_dir}Hiragino Mincho ProN.ttc'
@arastu
arastu / image_manipulation.py
Created May 4, 2021 13:51
Write rtl (Persian, Arabic, Hebrew) text on images using python and pillow
# First of all you need install *libraqm* on your machin.
# The Raqm library encapsulates the logic for complex text layouts and provides a convenient API.
# libraqm relies on the following libraries: FreeType, HarfBuzz, FriBiDi,
# make sure that you install them before installing libraqm if not available as package in your system.
# if you using macos you can install libraqm with homebrew
# $> brew install libraqm
# Pillow wheels since version 8.2.0 include a modified version of libraqm
@andelf
andelf / font.py
Created January 16, 2021 05:32
CJK Font for Rust embedded-graphics
from PIL import Image, ImageDraw, ImageFont
import PIL.features
# ! brew install libraqm
print('libraqm:', PIL.features.check('raqm'))
size = (320, 16)
"""
FORMAT = "RGB"
@andelf
andelf / crop-blue30.py
Last active April 12, 2024 12:56
Generate Chinese font for waveshare-epd
from PIL import Image, ImageDraw, ImageFont, ImageFilter
im = Image.open("./blue30.png")
POS = (1, 4)
X = POS[0] * 80
Y = POS[1] * 80
im1 = im.crop((X, Y, X + 30, Y + 30))
#!/usr/bin/python3
# -*- coding:utf-8 -*-
r"""テキストファイルを画像に変換
このファイル自体はサブコマンンド向けに作られた内部のクラスを実行する
ためのダミー
使い方
# 縦長(720x1280) 20桁 白色文字 黒色背景 ./font.ttf png形式
@korakot
korakot / thai_font.py
Last active June 30, 2022 05:18
Add thai font on Google Colaboratory notebook
!wget https://github.com/Phonbopit/sarabun-webfont/raw/master/fonts/thsarabunnew-webfont.ttf
# !pip install -U --pre matplotlib
import matplotlib as mpl
mpl.font_manager.fontManager.addfont('thsarabunnew-webfont.ttf') # 3.2+
mpl.rc('font', family='TH Sarabun New')
@korakot
korakot / thaisort.py
Created July 13, 2017 09:57
Thai Sort
import icu
thkey = icu.Collator.createInstance(icu.Locale('th_TH')).getSortKey
words = 'ไก่ ไข่ ก ฮา'.split()
print(sorted(words, key=thkey)) # ['ก', 'ไก่', 'ไข่', 'ฮา']
@eimg
eimg / mm2en.js
Last active May 5, 2022 08:31
Convert Myanmar numbers to English numbers
// INPUT: ၁၁.၁၂.၂၀၁၇
// OUTPUT: 11.12.2017
function mm2en(num) {
var nums = { '၀': '0', '၁': 1, '၂': 2, '၃': 3, '၄': 4 , '၅': 5, '၆': 6, '၇':7, '၈':8, '၉':9 };
return num.replace(/([၀-၉])/g, function(s, key) {
return nums[key] || s;
});
}
@HughP
HughP / UAX_29.py
Created March 30, 2015 06:10
PyICU
# We start by loading up PyICU.
import PyICU as icu
# Let's create a test text. Notice it contains some punctuation.
test = u"This is (\"a\") test!"
# We create a wordbreak iterator. All break iterators in ICU are really RuleBasedBreakIterators, and we need to tell it which locale to take the word break rules from. Most locales have the same rules for UAX#29 so we will use English.
wb = icu.BreakIterator.createWordInstance(icu.Locale.getEnglish())
# An iterator is just that. It contains state and then we iterate over it. The state in this case is the text we want to break. So we set that.