c++ - 使用python或c++将xml/html字符串转换为图像

标签 c++ python html image

我有以下 xml/html 字符串,想将其转换为 jpg 谁能知道我该怎么做?

<Text index="1" text="Hello Rizwan Ullah&#xD;" rotation="0" offsetX="182.7" offsetY="96.75" backgroundColor="10066329" backgroundAlpha="0.4" margin="0">
<![CDATA[<TEXTFORMAT LEADING="2">
<P ALIGN="LEFT">
<FONT FACE="arialfontB" SIZE="18" COLOR="#000000" LETTERSPACING="0" KERNING="0">
<B>H</B>
<FONT FACE="defaultFont">ello
<FONT SIZE="12"> 
<FONT SIZE="32">Rizwan</FONT> 
<FONT SIZE="24" COLOR="#FF0000">Ullah
<FONT SIZE="12"></FONT>
</FONT>
</FONT>
</FONT>
</FONT>
</P>
</TEXTFORMAT>]]>
<Transform x="182.7" y="96.75">a=1.347221851348877, b=0, c=0, d=1.347221851348877, tx=182.7, ty=96.75</Transform>
</Text>

最佳答案

Python 图像库 (PIL) 可以将文本呈现为图像:

来自已有问题的示例:

from PIL import Image
import ImageFont, ImageDraw

image = Image.new("RGBA", (288,432), (255,255,255))
usr_font = ImageFont.truetype("resources/HelveticaNeueLight.ttf", 25)
d_usr = ImageDraw.Draw(image)
d_usr = d_usr.text((105,280), "MYTEXT",(0,0,0), font=usr_font)

另见:

http://www.pythonware.com/products/pil/

Python Imaging Library - Text rendering

关于c++ - 使用python或c++将xml/html字符串转换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5741803/

相关文章:

c++ - 将 stdio.h 程序转换为 iostream

html - 带有 CSS 的图像周围的标题和内容

Python - 通过一周中的所有天对数据框进行排序

javascript - 以相对速度的简单视差滚动

HTML 5 文件系统如何增加持久存储

c++ - LPCTSTR 的非常奇怪的行为

c++ - C++如何知道子类调用父方法?

c++ - 段错误后会发生什么?

python - NLTK 将标记化的句子转换为同义词集格式

python - 装饰器运行错误: "UnboundLocalError: local variable ' count' referenced before assignment"