HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

imagegif

Description

The imagegif of Image for PHP output image to browser or file.

Syntax

imagegif(
    GdImage $image,
    resource|string|null $file = null
): bool

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().

file

The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly.

Return

Returns true on success or false on failure.

Caution: However, if libgd fails to output the image, this function returns true.

Examples

1 · image

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$return = imagegif($image);

var_export($return);
GIF87add�,dds��������ڋ�޼���H�扦�ʶ���L�����
�Ģ�L*�̦�    �J�Ԫ���j�ܮ�����N���
��������(8HXhx�������iX;true

2 · file

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$file = $_SERVER['DOCUMENT_ROOT'] . '/assets/gif/1.gif';

$return = imagegif($image, $file);

var_export($return);
true

3 · header

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

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

imagegif($image);
GIF87add�,dds��������ڋ�޼���H�扦�ʶ���L�����
�Ģ�L*�̦�    �J�Ԫ���j�ܮ�����N���
��������(8HXhx�������iX;

4 · path

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

$path = "/assets/gif/1.gif";
$file = $_SERVER['DOCUMENT_ROOT'] . $path;
imagegif($image, $file);

echo '<!doctype html>
<html>
<body>
    <img src="' . $path . '">
</body>
</html>';
<!doctype html>
<html>
<body>
    <img src="/assets/gif/1.gif">
</body>
</html>

5 · base64

<?

$width = 100;
$height = 100;
$image = imagecreatetruecolor($width, $height);

ob_start();

    imagegif($image);

$output = ob_get_clean();

echo '<!doctype html>
<html>
<body>
    <img src="data:image/gif;base64,' . base64_encode($output) . '">
</body>
</html>';
<!doctype html>
<html>
<body>
    <img src="data:image/gif;base64,R0lGODdhZABkAIAAAAQCBAAAACwAAAAAZABkAAACc4SPqcvtD6OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5LL5jE6r1+y2+w2Py+f0uv2Oz+v3/L7/DxgoOEhYaHiImKi4yNjo+AhpWAAAOw==">
</body>
</html>