Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

convert xml/html string to image using python or c++

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...