note 97214 modified in function.imagegif by danbrown
| From: | danbrown@php.net | Date: | Thu, 08 Apr 2010 14:53:59 +0000 |
| Subject: | note 97214 modified in function.imagegif by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168030@lists.php.net to get a copy of this message | ||
This is a suggestion for people who are using the function not to pass a NULL value for the
$filename argument, with a detailed explanation as to why as well as a suggested alternative.
It should be noted that, contrary to what the manual implies, an error will be returned if you
specify a NULL filename instead of simply omitting it.
For example:
<?php
function Test( $img, $filename = NULL )
{
$ok = imagegif( $img, $filename );
}
?>
This will return an image that contains errors. However, if you simply omit $filename altogether,
you'll be just fine.
To make the above function work error-free, do this:
<?php
function Test( $img, $filename = NULL )
{
if ( $filename == NULL )
{
$ok = imagegif( $img );
}
else
{
$ok = imagegif( $img, $filename );
}
}
?>
The manual somewhat inaccurately states the following for the $filename argument:
"If not set or NULL, the raw image stream will be outputted directly."
In fact, as I just demonstrated, this is misleading as it fails to mention that passing it as a NULL
value causes a broken (error) image to be displayed.
I would recommend you avoid this by simply making sure that you don't pass a NULL value for
$filename.
--was--
** THIS IS NOT A BUG REPORT! DO NOT DELETE IT! **
This is a suggestion for people who are using the function not to pass a NULL value for the
$filename argument, with a detailed explanation as to why as well as a suggested alternative.
It should be noted that, contrary to what the manual implies, an error will be returned if you
specify a NULL filename instead of simply omitting it.
For example:
function Test( $img, $filename = NULL )
{
$ok = imagegif( $img, $filename );
}
This will return an image that contains errors. However, if you simply omit $filename altogether,
you'll be just fine.
To make the above function work error-free, do this:
function Test( $img, $filename = NULL )
{
if ( $filename == NULL )
{
$ok = imagegif( $img );
}
else
{
$ok = imagegif( $img, $filename );
}
}
The manual somewhat inaccurately states the following for the $filename argument:
"If not set or NULL, the raw image stream will be outputted directly."
In fact, as I just demonstrated, this is misleading as it fails to mention that passing it as a NULL
value causes a broken (error) image to be displayed.
I would recommend you avoid this by simply making sure that you don't pass a NULL value for
$filename.
http://php.net/manual/en/function.imagegif.php