(PHP 4, PHP 5, PHP 7)
imagegif — 锟斤拷锟酵硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷
$image
[, string $filename
] ) : bool
imagegif() 锟斤拷 image
图锟斤拷锟斤拷 filename
为锟侥硷拷锟斤拷锟斤拷锟斤拷一锟斤拷
GIF 图锟斤拷image
锟斤拷锟斤拷锟斤拷 imagecreate() 锟斤拷
imagecreatefrom* 锟斤拷锟斤拷锟侥凤拷锟斤拷值锟斤拷
图锟斤拷锟绞轿� GIF87a锟斤拷锟斤拷锟斤拷锟斤拷锟� imagecolortransparent() 使图锟斤拷为透锟斤拷锟斤拷锟斤拷锟斤拷锟绞轿� GIF89a锟斤拷
image
锟斤拷图锟襟创斤拷锟斤拷锟斤拷(锟斤拷锟斤拷imagecreatetruecolor())锟斤拷锟截碉拷图锟斤拷锟斤拷源锟斤拷
filename
锟侥硷拷锟斤拷锟斤拷锟铰凤拷锟斤拷锟斤拷锟斤拷未锟斤拷锟矫伙拷为 NULL
锟斤拷锟斤拷锟斤拷直锟斤拷锟斤拷锟皆纪硷拷锟斤拷锟斤拷锟�
锟缴癸拷时锟斤拷锟斤拷 TRUE
锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
锟斤拷
Example #1 使锟斤拷 imagegif() 锟斤拷锟揭伙拷锟酵硷拷锟�
<?php
// 锟斤拷锟斤拷锟铰碉拷图锟斤拷实锟斤拷
$im = imagecreatetruecolor(100, 100);
// 锟斤拷锟矫憋拷锟斤拷为锟斤拷色
imagefilledrectangle($im, 0, 0, 99, 99, 0xFFFFFF);
//锟斤拷图锟斤拷锟斤拷写锟斤拷
imagestring($im, 3, 40, 20, 'GD Library', 0xFFBA00);
// 锟斤拷锟酵硷拷锟斤拷锟斤拷锟斤拷
header('Content-Type: image/gif');
imagegif($im);
imagedestroy($im);
?>
Example #2 使锟斤拷 imagegif() 锟斤拷一锟斤拷 PNG 转锟斤拷锟斤拷 GIF
<?php
// 锟斤拷锟斤拷 PNG
$png = imagecreatefrompng('./php.png');
// 锟斤拷 GIF 锟斤拷锟斤拷图锟斤拷
imagegif($png, './php.gif');
// 锟酵凤拷锟节达拷
imagedestroy($png);
// 锟疥工
echo 'Converted PNG image to GIF with success!';
?>
Note:
锟斤拷锟斤拷锟斤拷 GD 锟斤拷 1.6 锟斤拷锟斤拷锟叫碉拷 GIF 支锟街讹拷锟狡筹拷锟剿o拷锟斤拷锟节版本 2.0.28 锟叫硷拷锟剿伙拷锟斤拷锟斤拷锟斤拷锟绞癸拷锟斤拷锟叫� 锟芥本之锟斤拷锟� GD 锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟矫★拷 锟斤拷锟斤拷锟斤拷息锟斤拷 » GD Project 站锟姐。
锟斤拷锟铰达拷锟斤拷锟酵拷锟斤拷远锟斤拷锟斤拷 GD 支锟街碉拷图锟斤拷锟斤拷锟斤拷锟斤拷写锟斤拷锟斤拷植锟皆革拷锟矫碉拷 PHP 锟斤拷锟斤拷锟矫革拷锟斤拷锟侥达拷锟斤拷锟斤拷锟斤拷锟皆拷锟斤拷锟� header("Content-type: image/gif"); imagegif($im);锟斤拷
<?php
// 锟斤拷锟斤拷锟铰碉拷图锟斤拷实锟斤拷
$im = imagecreatetruecolor(100, 100);
// 锟斤拷锟斤拷锟斤拷锟酵硷拷锟斤拷锟斤拷一些锟斤拷锟斤拷
// 锟斤拷锟斤拷锟斤拷锟�
if(function_exists('imagegif'))
{
// 锟斤拷锟� GIF
header('Content-Type: image/gif');
imagegif($im);
}
elseif(function_exists('imagejpeg'))
{
// 锟斤拷锟� JPEG
header('Content-Type: image/jpeg');
imagejpeg($im, NULL, 100);
}
elseif(function_exists('imagepng'))
{
// 锟斤拷锟� PNG
header('Content-Type: image/png');
imagepng($im);
}
elseif(function_exists('imagewbmp'))
{
// 锟斤拷锟� WBMP
header('Content-Type: image/vnd.wap.wbmp');
imagewbmp($im);
}
else
{
imagedestroy($im);
die('No image support in this PHP server');
}
// 锟斤拷锟斤拷锟斤拷锟酵硷拷锟斤拷锟斤拷锟斤拷系母锟绞街伙拷锟斤拷痛锟斤拷诖锟斤拷锟斤拷头锟�
if($im)
{
imagedestroy($im);
}
?>
Note:
锟斤拷 PHP 3.0.18 锟斤拷 4.0.2 锟斤拷锟斤拷锟斤拷锟� imagetypes() 锟斤拷锟斤拷锟斤拷锟斤拷 function_exists() 锟斤拷锟斤拷锟斤拷欠锟街э拷锟侥筹拷锟酵硷拷锟斤拷式锟斤拷
<?php
if(imagetypes() & IMG_GIF)
{
header('Content-Type: image/gif');
imagegif($im);
}
elseif(imagetypes() & IMG_JPG)
{
/* ... etc. */
}
?>