【问题标题】:ie6 - gd and php image outputtingie6 - gd 和 php 图像输出
【发布时间】:2010-11-30 12:19:12
【问题描述】:

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

$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/weblog/2005/06/base64-ie/ 我看到图片,但在几秒钟内它们会隐藏起来......我真的不知道为什么。你能帮我解决这个问题吗?

【问题讨论】:

    标签: php image internet-explorer-6 gd


    【解决方案1】:

    数据 URI 方案 isn't supported in IE6 (nor IE7, apparently)。您需要将图像保存在某处,并将保存图像的 URL 提供为img src,或者您需要通过单独的脚本动态生成它并执行img src="path/to/image_generator.php" 之类的操作。

    【讨论】:

    • 图像生成器脚本的内容是这样的,我现在在我的页面中有什么?请举个例子好吗?
    • Request-URI Too Large - 我的图片太大,无法将它们传递给 url-query。
    • 是的,通过查询字符串将图像数据传递给图像生成器会很愚蠢。您需要向图像生成器传递一个唯一标识符,以便您找到图像 - 例如文件名、脚本中的 $i 等。
    【解决方案2】:

    ceejayoz 的方法可能是最好的,他说 IE6 不支持该方案是正确的。 Here is a page about how to do it in 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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-26
      • 2011-11-16
      • 2011-09-28
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多