导航首页 » 技术教程 » PHP:imagecreatefromgif()的用法_GD库图像处理函数
PHP:imagecreatefromgif()的用法_GD库图像处理函数 139 2023-12-15   

imagecreatefromgif

(PHP 4, PHP 5)

imagecreatefromgif — 由文件或 URL 创建一个新图象。

说明

resource imagecreatefromgif ( string $filename )

imagecreatefromgif() 返回一图像标识符,代表了从给定的文件名取得的图像。

Tip

如已启用fopen 包装器,在此函数中, URL 可作为文件名。关于如何指定文件名详见 fopen()。各种 wapper 的不同功能请参见 支持的协议和封装协议,注意其用法及其可提供的预定义变量。

参数

filename

GIF 图像的路径。

返回值

成功后返回图象资源,失败后返回 FALSE

范例

Example #1 处理创建过程中的错误

<?php
function LoadGif($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefromgif($imgname);

    /* See if it failed */
    if(!$im)
    {
        /* Create a blank image */
        $im = imagecreatetruecolor (150, 30);
        $bgc = imagecolorallocate ($im, 255, 255, 255);
        $tc = imagecolorallocate ($im, 0, 0, 0);

        imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);

        /* Output an error message */
        imagestring ($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

header('Content-Type: image/gif');

$img = LoadGif('bogus.image');

imagegif($img);
imagedestroy($img);
?>

以上例程的输出类似于:

注释

Note:

自 GD 库 1.6 版起所有的 GIF 支持都移除了,又在 GD 库 2.0.28 版起又加了回来。如果使用二者之间版本的 GD 库时本函数不可用。

Warning

Windows 版本的 PHP 在 4.3.0 版之前不支持通过此函数访问远程文件,即使已经启用 allow_url_fopen.


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103