将阿拉伯语文本导出为图像 [英] export arabic text as images
问题描述
我在UTF-8中有一堆阿拉伯文字。我试图显示此设备的设备不支持显示的阿拉伯语文本。因此,我需要将文本转换为图像。
I have a bunch of lines of Arabic text in UTF-8. The device I am trying to display this one does not support arabic text being displayed. Therefore, I need to convert the text into images.
我想将每行文本保存为具有特定宽度的图像。我也需要使用特定的字体。做这个的最好方式是什么?有没有人知道这里有用的工具?
I would like to save each line of text as an image with a specific width. I need to use a specific font as well. What is the best way to do this? Does anybody know of a tool that can be helpful here?
到目前为止我遇到的问题:
Problems I've run into so far:
PHP + GD:阿拉伯字母看起来是分开的,不应该像草书一样。
VB.net:我可以将每行文本转储到richtextbox中......但我不知道如何导出该控件的图像。
Flash:不支持从右到左文本。
PHP + GD: Arabic letters appear seperated and not in cursive as they should. VB.net: I can dump each line of text into a richtextbox... but I don't know how to export the image of just that control. Flash: no support for right to left text.
推荐答案
至于阿拉伯语,你需要一个库来反向字符/字形 PHP / GD 。见例如 http://sourceforge.net/projects/ar-php/ 或 http://www.ar-php.org/ 。
As for Arabic, you need a library to reverse chars/glyphs for PHP/GD. see e.g. http://sourceforge.net/projects/ar-php/ or at http://www.ar-php.org/.
确保 PHP文件编码 unicode / UTF 。
eg >打开记事本>另存为>编码为UTF-8:
Make sure your PHP file encoding is in unicode/UTF.
e.g. > open Notepad > Save As > encoding as UTF-8:
使用 imagettftext 的PHP中阿拉伯字体排版的示例用法:
Sample usage for Arabic typography in PHP using imagettftext:
<?php
// The text to draw
require('./I18N/Arabic.php');
$Arabic = new I18N_Arabic('Glyphs');
$font = './DroidNaskh-Bold.ttf';
$text = $Arabic->utf8Glyphs('لغةٌ عربيّة');
// Create the image
$im = imagecreatetruecolor(600, 300);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 599, 299, $white);
// Add the text
imagettftext($im, 50, 0, 90, 90, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im, "./output_arabic_image.png");
echo 'open: ./output_arabic_image.png';
imagedestroy($im);
?>
输出:
这篇关于将阿拉伯语文本导出为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!