相关疑难解决方法(0)

如何在HTML中显示Base64图像?

我无法在线显示Base64图像.

有人能指出我正确的方向吗?

<!DOCTYPE html>
<html>
  <head>
    <title>Display Image</title>
  </head>
  <body>
    <img style='display:block; width:100px;height:100px;' id='base64image'                 
       src='data:image/jpeg;base64, LzlqLzRBQ...<!-- base64 data -->' />
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

html base64 inline image

506
推荐指数
12
解决办法
95万
查看次数

使用python动态地将matplotlib图像提供给Web

这个问题在这里以类似的方式提出,但答案是我的头脑(我是python和web开发的新手),所以我希望有一个更简单的方法或者可以用不同的方式解释.

我正在尝试使用matplotlib生成一个图像并在没有先将文件写入服务器的情况下提供它.我的代码可能有点傻,但它是这样的:

import cgi
import matplotlib.pyplot as pyplot
import cStringIO #I think I will need this but not sure how to use

...a bunch of matplotlib stuff happens....
pyplot.savefig('test.png')

print "Content-type: text/html\n"
print """<html><body>
...a bunch of text and html here...
<img src="test.png"></img>
...more text and html...
</body></html>
"""
Run Code Online (Sandbox Code Playgroud)

我认为不是做pyplot.savefig('test.png'),而是应该创建一个cstringIO对象,然后执行以下操作:

mybuffer=cStringIO.StringIO()
pyplot.savefig(mybuffer, format="png")
Run Code Online (Sandbox Code Playgroud)

但我很失落.我见过的所有例子(例如http://lost-theory.org/python/dynamicimg.html)都涉及到类似的事情.

print "Content-type: image/png\n"
Run Code Online (Sandbox Code Playgroud)

我不知道如何将它与我已经输出的HTML集成.

python cgi matplotlib

20
推荐指数
4
解决办法
2万
查看次数

标签 统计

base64 ×1

cgi ×1

html ×1

image ×1

inline ×1

matplotlib ×1

python ×1