使用python或c ++将xml / html字符串转换为图像 [英] convert xml/html string to image using python or c++

查看:139
本文介绍了使用python或c ++将xml / html字符串转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的 xml / html 字符串,并且想将它转换为 jpg 任何人都知道我怎么可能

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


解决方案

Python影像库(PIL) image:

来自已有问题的示例:

  from PIL import Image 
import ImageFont,ImageDraw
$ b $ 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图像库 - 文本呈现


I have following xml/html string and want to convert it to jpg can any one know how could I achieve this?

<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 Imaging Library (PIL) can render text to an image:

Example from a pre-existing question:

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)

See also:

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

Python Imaging Library - Text rendering

这篇关于使用python或c ++将xml / html字符串转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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