关于php里的imagegif()函数

王朝php·作者佚名  2004-12-28
窄屏简体版  字體: |||超大  

imagegif

(PHP 3, PHP 4 )

imagegif -- 以 GIF 格式将图像输出到浏览器或文件

说明

int imagegif ( resource image [, string filename])

imagegif() 从 image 图像以 filename 为文件名创建一个 GIF 图像。image 参数是 imagecreate() 函数的返回值。

图像格式为 GIF87a。如果用了 imagecolortransparent() 使图像为透明,则其格式为 GIF89a。

filename 参数为可选,如果省略,则原始图像流将被直接输出。通过 header() 发送 Content-type: image/gif 可以使 PHP 脚本直接输出 GIF 图像。

注: 不过从 GD 库 1.6 起所有的 GIF 支持都移除了,如果使用这些 GD 库时本函数不可用。希望在 2004 年中期能够发布支持 GIF 的 GD 库。更多信息见 GD Project 站点。

以下代码段通过自动检测 GD 支持的图像类型来写出移植性更好的 PHP 程序。用更灵活的代码替代了原来的 header("Content-type: image/gif"); imagegif($im);:

PHP代码:

<?php

if (function_exists("imagegif")) {

header ("Content-type: image/gif");

imagegif ($im);

}

elseif (function_exists("imagejpeg")) {

header ("Content-type: image/jpeg");

imagejpeg ($im, "", 0.5);

}

elseif (function_exists("imagepng")) {

header ("Content-type: image/png");

imagepng ($im);

}

elseif (function_exists("imagewbmp")) {

header ("Content-type: image/vnd.wap.wbmp");

imagewbmp ($im);

}

else

die("No image support in this PHP server");

?>

注: 自 PHP 3.0.18 和 4.0.2 起可以用 imagetypes() 函数代替 function_exists() 来检查是否支持某种图像格式:

PHP代码:

<?php

if (imagetypes() & IMG_GIF) {

header ("Content-type: image/gif");

imagegif ($im);

}

elseif (imagetypes() & IMG_JPG) {

... etc.

?>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航