note 40517 added to function.gd-info
| From: | HaganFox-Qdig dot SourceForge dot net at rn2 dot php dot net | Date: | Sat, 06 Mar 2004 03:41:09 +0000 |
| Subject: | note 40517 added to function.gd-info | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-66334@lists.php.net to get a copy of this message | ||
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.";
}
----
Manual Page -- http://www.php.net/manual/en/function.gd-info.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40517
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40517&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40517&report=yes
Search -- http://master.php.net/manage/user-notes.php