note 40517 deleted from function.gd-info by philip
| From: | philip@php.net | Date: | Mon, 09 Aug 2004 10:37:49 +0000 |
| Subject: | note 40517 deleted from function.gd-info by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74306@lists.php.net to get a copy of this message | ||
Note Submitter: Hagan Fox - Qdig.SourceForge.net
----
For my image gallery script I need to know if the GD version is 1.x or >=2 because I want to use
TrueColor-capable functions if available, otherwise have the script fall back to the HiColor
versions. To that end, I wrote a function that grabs just the major version number of the installed
GD extension. This function works on versions of PHP older than 4.3.
/**
* Get which version of GD is installed, if any.
*
* Returns the version (1 or 2) of the GD extension.
*/
function gdVersion() {
if (! extension_loaded('gd')) { return; }
ob_start();
phpinfo(8);
$info=ob_get_contents();
ob_end_clean();
$info=stristr($info, 'gd version');
preg_match('/\d/', $info, $gd);
return $gd[0];
} // end function gdVersion()
// The function is easy to use.
if ($gdv = gdVersion()) {
if ($gdv >=2) {
echo 'imageCreateTruecolor() and imageCopyResampled() functions may be used.';
} else {
echo 'imageCreate() and imageCopyResized() functions must be used.';
}
} else {
echo "The GD extension isn't loaded.";
}