Perl-CGI图像在浏览器中显示为二进制 [英] Perl-CGI Image is displayed in browser as binary

查看:68
本文介绍了Perl-CGI图像在浏览器中显示为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个小插件,该插件通过Perl GD生成图像并将其显示在浏览器中。到目前为止,一切正常,除了图像以二进制字符流显示。
使用Google这类问题相当烦人,因为我读过有关将文件临时保存到硬盘上的信息,我希望避免这种情况。

I was programming a little plugin, which generates an image via Perl GD and displays it in the browser. So far everything works correct, except that the image is displayed in binary character stream. It's rather annoying to google this kind of problem, because I read about temporarily saving the file to the hard disk, which I would love to avoid.

这是到目前为止我拥有的代码:

This is the code I have so far:

$image = $print->png; ## the image was created correctly, I was able to 
#view it if I saved it on the local drive

my $cgi = new CGI;

print $cgi -> header(),
  $cgi -> start_html(),
  $cgi -> h1('Bernd'),
  $cgi -> header(-type=>'image/png');
  binmode STDOUT;
  print $image;
print $cgi -> end_html();

要调用CGI模块的特殊方法吗?因为找不到我,所以我有些困惑。

To I have to call a special method of the CGI module? Because I did not find one I am a little bit confused.

任何帮助都是值得的。
预先感谢!

Any help is appreciated. Thanks in advance!

推荐答案

当是PNG时,图像必须是单独的资源/ URL,指向HTML img 元素或类似的元素,而不是嵌入文档中的文字流。这些是HTML的基础知识,如果您不熟悉HTML,则可以获取一本网络编程书籍。

When it's a PNG, the image must be a separate resource/URL, pointed to by a HTML img element or similar, not flow text embedded into the document. These are the basics of HTML, get a Web programming book if you are not familiar with that.

可以将图像格式更改为嵌入式SVG,或者重写该程序,以便它会创建一个 img 元素,以及另一个创建图像HTTP响应的程序。

Either change your image format to inline SVG, or rewrite the program so that it creates an img element, and another program creating the image HTTP response.

可以合并原始元素程序(HTML响应)和创建图像响应的程序,但我不建议新手使用。

It is possible to combine the original program (HTML response) with the one creating the image response, but I don't recommend this for newcomers.

这篇关于Perl-CGI图像在浏览器中显示为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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