显示使用 imagecreatefromstring 创建的图像
假设我的代码看起来像这样:
<?PHP
//
//... stuff here
//
$im = imagecreatefromstring( $imageData );
echo "<img src=" . /* what goes here? */ . "alt=\"the image\" />";
//
// more stuff here
//
?>
我该替换什么/* 这里放什么? */ 这样我的图像数据就会显示?
谢谢。
Let's say I have the code that looks something like:
<?PHP
//
//... stuff here
//
$im = imagecreatefromstring( $imageData );
echo "<img src=" . /* what goes here? */ . "alt=\"the image\" />";
//
// more stuff here
//
?>
What do I replace /* what goes here? */ with so my image data will display?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您突出显示的位置是 < 的所谓
src
属性代码>img HTML 标签文档。该值是所谓的 URIDocs。在您的情况下,您希望该 URI 指向有问题的图像数据。您尚未指定图像应输出为哪种类型,因此在以下示例中我将假设它是 PNG 图像。
您现在需要将图像数据转换为 URI。从图像数据创建的最直接的 URI 是所谓的
data:
URIWikipedia:即使这是最直接的方法,也不总是建议这样做,因为图像数据将与 HTML 一起返回到浏览器。如果图像很大,这通常被认为是一种开销。
您也可以在其中放置任何其他 URI,而不是使用
data:
URI,例如指向服务器上返回图像的 PHP 脚本的 HTTP URI。这样的脚本可以非常简单:这与 Marc B 建议的相当,也请参阅他的回答。
The location you highlighted is the so called
src
attribute of theimg
HTML-tagDocs. The value is a so called URIDocs.In your case you want that URI to point to the image data in question. You have not specified which type the image should be output as, so I will assume it's a PNG image in the following example.
You now need to convert your image data into an URI. The most straight forward URI to create from the image data is a so called
data:
URIWikipedia:Even this is the most straight forward way, it is not always recommended to do so because the image data will be returned with the HTML to the browser. If the image is large, this is commonly considered an overhead.
Instead of using the
data:
URI you can place any other URI in there as well, for example a HTTP URI that is pointing to a PHP script on your server that is returning the image. Such a script can be very simple:This is comparable to what Marc B suggested, see his answer as well.
应该就是你所需要的。按照原样使用图像标签执行此操作,您需要将图像输出到临时文件并将图像标签指向该文件(这会产生第二个 HTTP 请求),或者使用 数据网址。
should be all you need. Doing it with the image tag as you are, you'd need to output the image to a temporary file and point the image tag at that (which incurs a second HTTP request), or use a data url.
我认为你可以做这样的事情......
I think you can do something like this...
您必须首先将资源保存到文件中,或者使用类似
的内容将其输出imagepng()
在一个单独的请求中。有关详细信息,请参阅
imagecreatefromstring()
文档。如果您想使用数据 URI 方案,您可以尝试以下操作:
You have to save the resource to a file first or output it using something like
imagepng()
in a separate request.See
imagecreatefromstring()
documentation for more information.If you want to use a Data URI scheme, you can try this instead: