ie6 - gd 和 php 图像输出

发布于 2024-08-05 09:08:02 字数 1074 浏览 2 评论 0原文

我正在尝试用灰度滤镜显示图像。这是我的代码:

$images = glob('gallery/*small*');
shuffle($images);
array_splice($images, 3);

$imgHandles = array();
$imgBuffered = array();
for( $i = 0; $i < 3; $i++)
{  
   $imgHandles[$i] = imagecreatefromstring( file_get_contents($images[$i]) ); 
   imagefilter( $imgHandles[$i], IMG_FILTER_GRAYSCALE ); 

   ob_start();
   imagepng( $imgHandles[$i] ); 
   $imgBuffered[$i] = ob_get_contents();
   ob_end_clean();
   imagedestroy( $imgHandles[$i] ); 
} 

输出:

for( $i = 0; $i < 3; $i++ )
{  
   echo "<a href=\"gallery.php\">
   <img class=\"photo\" src='data:image/png;base64,".base64_encode( $imgBuffered[$i] )."' /></a>";                                                                                    
}

在 Opera、ff、chrome、safari 中一切都很好,但 ie6 不显示图像。为什么?

我制作了如下页面的代码: http://dean.edwards.name/博客/2005/06/base64-ie/ 我看到照片,但几秒钟后它们就隐藏起来了……我真的不知道为什么。你能帮我处理这些事情吗?

i'm trying to show image with grayscale-filter. Here is my code:

$images = glob('gallery/*small*');
shuffle($images);
array_splice($images, 3);

$imgHandles = array();
$imgBuffered = array();
for( $i = 0; $i < 3; $i++)
{  
   $imgHandles[$i] = imagecreatefromstring( file_get_contents($images[$i]) ); 
   imagefilter( $imgHandles[$i], IMG_FILTER_GRAYSCALE ); 

   ob_start();
   imagepng( $imgHandles[$i] ); 
   $imgBuffered[$i] = ob_get_contents();
   ob_end_clean();
   imagedestroy( $imgHandles[$i] ); 
} 

And outputting:

for( $i = 0; $i < 3; $i++ )
{  
   echo "<a href=\"gallery.php\">
   <img class=\"photo\" src='data:image/png;base64,".base64_encode( $imgBuffered[$i] )."' /></a>";                                                                                    
}

In opera, ff, chrome, safari everything is fine, but ie6 doesn't show images. Why?

I made code like at page: http://dean.edwards.name/weblog/2005/06/base64-ie/
I see pictures, but in some seconds they hide... I really don't know why. Can you help me with this stuff?

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

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

发布评论

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

评论(2

风追烟花雨 2024-08-12 09:08:02

数据 URI 方案IE6 不支持(显然也不支持 IE7)。您需要将图像保存在某处,并将保存的图像的 URL 作为 img src 提供,或者您需要通过单独的脚本动态生成它并执行类似 的操作>img src="path/to/image_generator.php"

The data URI scheme isn't supported in IE6 (nor IE7, apparently). You'll need to save the image somewhere and provide the URL to the saved image as the img src, or you'll need to generate it on the fly via a separate script and do something like img src="path/to/image_generator.php".

走野 2024-08-12 09:08:02

ceejayoz 的方法可能是最好的,他/她说 IE6 不支持该方案是正确的。 这里有一个关于如何在 IE 中执行此操作的页面,但是我希望您有充分的理由不使用 /path/to/image_generator.php 版本。

为此,您可以创建一个仅执行 imagepng 操作的脚本,然后发送标头,向浏览器指示相关图像是 png。例如,

img_generate.php

$images = glob('gallery/*small*');

$img_to_generate=intval($_GET['image_to_generate']);



$imgHandle = imagecreatefromstring( file_get_contents($images[$img_to_generate]) ); 
imagefilter( $imgHandle, IMG_FILTER_GRAYSCALE ); 

header('Content-type:image/png');//tell the browser what to expect
imagepng( $imgHandle ); //output the image
imagedestroy( $imgHandles ); //clean up

然后在你的html中

<img src="/path/to/img_generate.php?image_to_generate=0" alt="image 0" />
<img src="/path/to/img_generate.php?image_to_generate=1" alt="image 1" />
<img src="/path/to/img_generate.php?image_to_generate=2" alt="image 2" />

ceejayoz's approach is probably best, and he\she is correct in saying that the scheme isn't supported in IE6. Here is a page about how to do it in IE, but I hope you have a good reason for not doing the /path/to/image_generator.php version.

To do that, you would create a script that just does imagepng, for example, and then sends headers indicating to the browser that the image in question is a png. e.g.,

img_generate.php:

$images = glob('gallery/*small*');

$img_to_generate=intval($_GET['image_to_generate']);



$imgHandle = imagecreatefromstring( file_get_contents($images[$img_to_generate]) ); 
imagefilter( $imgHandle, IMG_FILTER_GRAYSCALE ); 

header('Content-type:image/png');//tell the browser what to expect
imagepng( $imgHandle ); //output the image
imagedestroy( $imgHandles ); //clean up

and then in your html

<img src="/path/to/img_generate.php?image_to_generate=0" alt="image 0" />
<img src="/path/to/img_generate.php?image_to_generate=1" alt="image 1" />
<img src="/path/to/img_generate.php?image_to_generate=2" alt="image 2" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文