imagecreatefromgif

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecreatefromgif由文件或 URL 創(chuàng)建一個新圖象。

說明

imagecreatefromgif(string $filename): resource

imagecreatefromgif() 返回一圖像標(biāo)識符,代表了從給定的文件名取得的圖像。

小技巧

如已啟用fopen 包裝器,在此函數(shù)中, URL 可作為文件名。關(guān)于如何指定文件名詳見 fopen()。各種 wapper 的不同功能請參見 支持的協(xié)議和封裝協(xié)議,注意其用法及其可提供的預(yù)定義變量。

參數(shù)

filename

GIF 圖像的路徑。

返回值

成功后返回圖象對象,失敗后返回 false。

范例

示例 #1 處理創(chuàng)建過程中的錯誤

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

    
/* See if it failed */
    
if(!$im)
    {
        
/* Create a blank image */
        
$im imagecreatetruecolor (15030);
        
$bgc imagecolorallocate ($im255255255);
        
$tc imagecolorallocate ($im000);

        
imagefilledrectangle ($im0015030$bgc);

        
/* Output an error message */
        
imagestring ($im155'Error loading ' $imgname$tc);
    }

    return 
$im;
}

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

$img LoadGif('bogus.image');

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

以上例程的輸出類似于:

例子的輸出: 處理創(chuàng)建 GIF 過程中的錯誤

注釋

注意:

自 GD 庫 1.6 版起所有的 GIF 支持都移除了,又在 GD 庫 2.0.28 版起又加了回來。如果使用二者之間版本的 GD 庫時本函數(shù)不可用。