Ruby linux CLI:如何将阿拉伯语文本渲染为位图
我想用命令行界面将阿拉伯语文本绘制成位图(bmp或png) 我试过imagemagick和RMagick,但我遇到了RTL语言问题。我所有的渲染都是从左到右的。谷歌也帮不上忙 要求:Ruby linux CLI:如何将阿拉伯语文本渲染为位图,ruby,linux,imagemagick,arabic,rmagick,Ruby,Linux,Imagemagick,Arabic,Rmagick,我想用命令行界面将阿拉伯语文本绘制成位图(bmp或png) 我试过imagemagick和RMagick,但我遇到了RTL语言问题。我所有的渲染都是从左到右的。谷歌也帮不上忙 要求: ./render "لوحة المفاتيح" out.png 将给出一个位图: ل 谁能给我一些成功的结果 谁能给我一些成功的结果 我可以。我使用ImageMagick中的转换: echo لوحة المفاتيح > text.txt && \ convert -size 300x2
./render "لوحة المفاتيح" out.png
将给出一个位图:
ل
谁能给我一些成功的结果
谁能给我一些成功的结果
我可以。我使用ImageMagick中的转换
:
echo لوحة المفاتيح > text.txt && \
convert -size 300x200 \
-background white \
-fill black \
-font /usr/share/fonts/truetype/droid/DroidNaskh-Regular.ttf \
-pointsize 24 \
-gravity Center \
label:@text.txt \
text.png
结果是:
一些注意事项:
对于阿拉伯语排版,您可能希望使用Inkscape 0.9如下(Window7 cmd): 其中,ar.svg是:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="400"
height="100"
version="1.1">
<text
xml:space="preserve"
style="font-size:30px;font-style:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:'Droid Arabic Naskh';font-weight:bold;"
x="10" y="90"
><tspan>لغةٌ عربيّةٌ</tspan>
</text>
</svg>
谢谢,但这是不正确的,阿拉伯语是从右到左的,正确的应该是:“对不起,我没有注意到你问题的RTL部分:-/没关系,我不懂阿拉伯语,也不认识任何字符。确实非常令人困惑。我注意到设置dpi(例如使用
--dpi=500
)会影响字体大小,但我没有进一步研究:)
inkscape "ar.svg" --export-png="C:\Users\Path\TO\output\arabicthabit.png" --export-dpi="900,900" --export-background="rgb(100%,100%,100%)"
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
width="400"
height="100"
version="1.1">
<text
xml:space="preserve"
style="font-size:30px;font-style:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:'Droid Arabic Naskh';font-weight:bold;"
x="10" y="90"
><tspan>لغةٌ عربيّةٌ</tspan>
</text>
</svg>
from wand.image import Image as wImage
from wand.display import display as wdiplay
from wand.drawing import Drawing
from wand.color import Color
import arabic_reshaper
from bidi.algorithm import get_display
reshaped_text = arabic_reshaper.reshape(u'لغةٌ عربيّة')
artext = get_display(reshaped_text)
fonts = ['C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\DroidNaskh-Bold.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit-Bold-Oblique.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit-Bold.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\Thabit-Oblique.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\majalla.ttf',
'C:\\Users\\PATH\\TO\\FONT\\Thabit-0.02\\majallab.ttf',
]
draw = Drawing()
img = wImage(width=1200,height=(len(fonts)+2)*60,background=Color('#ffffff'))
#draw.fill_color(Color('#000000'))
draw.text_alignment = 'right';
draw.text_antialias = True
draw.text_encoding = 'utf-8'
#draw.text_interline_spacing = 1
#draw.text_interword_spacing = 15.0
draw.text_kerning = 0.0
for i in range(len(fonts)):
font = fonts[i]
draw.font = font
draw.font_size = 40
draw.text(img.width / 2, 40+(i*60),artext)
print draw.get_font_metrics(img,artext)
draw(img)
draw.text(img.width / 2, 40+((i+1)*60),u'ناصر test')
draw(img)
img.save(filename='C:\\PATH\\OUTPUT\\arabictest.png'.format(r))
wdiplay(img)