图像到浏览器而不保存

发布于 2024-10-19 19:30:50 字数 418 浏览 6 评论 0原文

如何将图像从内存传输到浏览器而不保存。

例如:

 function getImage()
 {

   $imageFile = imagecreatefromjpeg('Map.jpg');
   $imageObject = imagecreatefrompng('image2.png');
   imagealphablending($imageFile, true);    
   imagecopy(....);
   $ret = array($imageFile, $imageObject) ;  
   return $ret
 }
 <?php $ret = getImage(); ?>
 <img src = <?php $ret[0];? alt=''>

如果不保存,这可能吗?

How can I put image from the memory to the browser, without saving.

For example:

 function getImage()
 {

   $imageFile = imagecreatefromjpeg('Map.jpg');
   $imageObject = imagecreatefrompng('image2.png');
   imagealphablending($imageFile, true);    
   imagecopy(....);
   $ret = array($imageFile, $imageObject) ;  
   return $ret
 }
 <?php $ret = getImage(); ?>
 <img src = <?php $ret[0];? alt=''>

Is this possible, without saving?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

念﹏祤嫣 2024-10-26 19:30:50

是的,

只需尝试 imagejpeg($img);

并将其放入渲染图像的 PHP 脚本的 路径中,

请参阅示例:http://php.net/manual/en/function.imagecreatefromjpeg.php

Yes,

Just try imagejpeg($img);

and put into <img src= path to the PHP script which render the image

See sample at: http://php.net/manual/en/function.imagecreatefromjpeg.php

心碎无痕… 2024-10-26 19:30:50

也许如果您将图像编码为 base64 并像这样使用它,它会起作用:

 <?php
    $img_str = base64_encode($imgbinary);
    echo '<img src="data:image/jpg;base64,'.$img_str.'" />';
    ?>

HTML:

<img src="data:image/jpg;base64,R0lGODlhCgAKAJEAAAAAAP///81Wv81WvyH5BAEAAAMALAAAAAAKAAoAAAIUjIViq+x7QpunwXoZ lXFu/mjIUgAAOw==" alt="image" />

我推断您想在一个请求中执行此操作。

Maybe if you would code your image to base64 and use it like that, it would work:

 <?php
    $img_str = base64_encode($imgbinary);
    echo '<img src="data:image/jpg;base64,'.$img_str.'" />';
    ?>

HTML:

<img src="data:image/jpg;base64,R0lGODlhCgAKAJEAAAAAAP///81Wv81WvyH5BAEAAAMALAAAAAAKAAoAAAIUjIViq+x7QpunwXoZ lXFu/mjIUgAAOw==" alt="image" />

I infered that you want to do this in one request.

筑梦 2024-10-26 19:30:50

您应该有一个发送正确标头的脚本,然后浏览器应将其识别为图像。类似于:

<?php
ob_start();
// assuming you have image data in $imagedata
$length = strlen($imagedata);
header('Last-Modified: '.date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: '.$length);
header('Content-Type: image/jpeg');
print($imagedata);
ob_end_flush();

?>

You should have a script which sends proper headers and then it should be recognized as an image by the browser. Something like:

<?php
ob_start();
// assuming you have image data in $imagedata
$length = strlen($imagedata);
header('Last-Modified: '.date('r'));
header('Accept-Ranges: bytes');
header('Content-Length: '.$length);
header('Content-Type: image/jpeg');
print($imagedata);
ob_end_flush();

?>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文