将阿拉伯语文本导出为图像 [英] export arabic text as images

查看:33
本文介绍了将阿拉伯语文本导出为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆 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:我可以将每一行文本转储到富文本框中...但我不知道如何导出该控件的图像.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/广东.见例如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.
例如> 打开记事本 > 另存为 > 编码为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆