将阿拉伯语文本导出为图像
我有一堆 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
方法有很多; 例如,使用 Windows.Forms,我认为您:
There are many ways; using Windows.Forms for example, I think you:
我不确定您是否仍在等待答案,但对于您的问题有非常干净整洁的解决方案。 您可以根据 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.
我听说 pango 可以很好地处理阿拉伯语布局。 不过还没用过。
更新:
实用程序
pango-view
可以用任何语言呈现文本并将其输出为图像,或者您也可以提供文本作为选项:
您还可以指定宽度:
<< 或者
,有一些程序使用 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 imageor you can supply the text as an option as well:
You can also specify a width:
<< 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.
至于阿拉伯语,您需要一个库来为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 中使用阿拉伯语排版的示例:
输出:
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:
Outputs: