将阿拉伯语文本导出为图像

发布于 2024-08-01 12:58:15 字数 290 浏览 8 评论 0原文

我有一堆 UTF-8 格式的阿拉伯文本。 我尝试显示此设备的设备不支持显示阿拉伯语文本。 因此,我需要将文本转换为图像。

我想将每行文本保存为具有特定宽度的图像。 我还需要使用特定的字体。 做这个的最好方式是什么? 有人知道这里有一个有用的工具吗?

到目前为止我遇到的问题:

PHP + GD:阿拉伯字母分开显示,而不是应有的草书形式。 VB.net:我可以将每行文本转储到 Richtextbox 中...但我不知道如何导出该控件的图像。 Flash:不支持从右到左的文本。

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: 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

有木有妳兜一样 2024-08-08 12:58:15

方法有很多; 例如,使用 Windows.Forms,我认为您:

  • 创建一个空的 Image 实例; 我认为此时您定义了图像的尺寸
  • 使用 Graphics.FromImage 方法从 Image 创建一个 Graphics 实例
  • 调用 Control (RichTextBox) 的方法,该方法告诉它自行绘制:并向该方法传递 Graphics与您的图像关联的实例,以便它将自身绘制到图像上。

There are many ways; using Windows.Forms for example, I think you:

  • Create an empty Image instance; I think that at this point you define the image's dimensions
  • Create a Graphics instance from the Image, using the Graphics.FromImage method
  • Invoke the method of the Control (the RichTextBox) which tells it to paint itself: and to that method, pass the Graphics instance associated with your image, so that it paints itself onto the image.
七七 2024-08-08 12:58:15

我不确定您是否仍在等待答案,但对于您的问题有非常干净整洁的解决方案。 您可以根据 CSS 类将任何文本(包括 RTL)更改为图像。 但我首先告诉你,PHP 和 GD 无论如何,对 rtl 文本没有任何好处。 您应该尝试基于宽度的 asp.net 文本替换。

有一次我走同样的路,挣扎了好几天。 这是你应该做的。

首先到以下地址查看教程并下载文件。
http://weblogs.asp.net /yaneshtyagi/archive/2008/11/07/text-to-image-convertor.aspx

其次,您需要一个 asp.net 服务器。 您可以安装它,也可以使用这些虚拟服务器之一,例如 mono asp.net 服务器,或者您可以使用 Visual Web Developer。

您将获得的代码将文本转换为单行图像,但您可以指定宽度。 在这种情况下,长行文本会缩小并变得难以辨认。 您需要的是根据指定的宽度进行文本换行。

此链接中解释了如何更改 fontwriter.ashx 中的代码以实现文本换行。 http://www.codeproject.com/Questions /189513/Dynamic-Image-Replacement-Method-with-Csharp.aspx

第三步通过 asp.net 服务器运行您的页面。 获得图像后,可以保存它,右键单击并另存为,使用 Firefox,到目前为止,Firefox 效果最好。

现在,所有文本都转换为图像,原始文本将作为 alt 标签添加到图像中。 希望能帮助到你。

我计划很快发布有关该问题的教程。 稍后查看 www.codeproject.com。

I am not sure if you still waiting for an answer but there is very clean and neat solution for your problem. You can change any text, including rtl, to image based on their css class. But let me tell you first, PHP and GD what ever, doesn't do any good for rtl text. You should try asp.net text replacement based on width.

Once I walked the same path and struggled for days. Here is what you should do.

First go to following address and see the tutorial and download the files.
http://weblogs.asp.net/yaneshtyagi/archive/2008/11/07/text-to-image-convertor.aspx

Second you need an asp.net server. You can install it or you can use one of those virtual server, such as mono asp.net server, or you can use visual web developer.

The code you will get converts the text into a single line image, though you can specify width. In that case long line of text shrink and becomes illegible. What you need is to text wrap based on specified width.

Here in this link that explains how to alter the code in fontwriter.ashx to achieve text wrap. http://www.codeproject.com/Questions/189513/Dynamic-Image-Replacement-Method-with-Csharp.aspx

Third run the your page via asp.net server. Once you have the images you can save it, right click and save as, with firefox, firefox works best so far.

Now, all the text is converted into images and original text will be added to image as alt tag. Hope it helps.

I am planning to post a tutorial on the issue soon. Check www.codeproject.com later.

百善笑为先 2024-08-08 12:58:15

我听说 pango 可以很好地处理阿拉伯语布局。 不过还没用过。

更新:

实用程序 pango-view 可以用任何语言呈现文本并将其输出为图像

$ pango-view input_file.txt --no-display --output=image.png

,或者您也可以提供文本作为选项:

$ pango-view --no-display --output=image.png --text="your sentence"

您还可以指定宽度:

--width=50 -wrap=word

<< 或者

,有一些程序使用 unicode 字符来表示上下文阿拉伯字母形式并处理文本,并使其在无法正确呈现阿拉伯文本的系统上正确呈现。

以下是我所知道的:

它们都是开源的,所以即使您不使用这些语言中的任何一种,您也可以研究代码并创建您选择的编程语言的解决方案。

I've heard that pango handles Arabic layout pretty well. haven't used it though.

Update:

The utility pango-view can render text in any language and output it as an image

$ pango-view input_file.txt --no-display --output=image.png

or you can supply the text as an option as well:

$ pango-view --no-display --output=image.png --text="your sentence"

You can also specify a width:

--width=50 -wrap=word

<< end of update

Alternatively, there are a few programs that use unicode characters that represent contextual Arabic letter forms and process text and make it render properly on systems that can't render Arabic text properly.

Here are the ones I know of:

They're all open source, so even if you don't use any of these languages, you can study the code and create a solution in your programming language of choice.

情深已缘浅 2024-08-08 12:58:15

至于阿拉伯语,您需要一个库来为PHP/GD反转字符/字形。 请参阅 http://sourceforge.net/projects/ar-php/ 或位于 < a href="http://www.ar-php.org/" rel="nofollow noreferrer">http://www.ar-php.org/。

确保您的PHP 文件编码采用unicode/UTF
例如> 打开记事本> 另存为> 编码为 UTF-8:

使用 imagettftext 在 PHP 中使用阿拉伯语排版的示例:

<?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); 
?>

输出:

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/.

Make sure your PHP file encoding is in unicode/UTF.
e.g. > open Notepad > Save As > encoding as UTF-8:

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); 
?>

Outputs:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文