BCS website placeholder and testbed (circa Nov 2003)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

55 lines
1.4 KiB

<?php
/**
* Get which version of GD is installed, if any.
*
* Returns the version (1 or 2) of the GD extension.
*/
function gdVersion($user_ver = 0)
{
if (! extension_loaded('gd')) { return; }
static $gd_ver = 0;
// Just accept the specified setting if it's 1.
if ($user_ver == 1) { $gd_ver = 1; return 1; }
// Use the static variable if function was called previously.
if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; }
// Use the gd_info() function if possible.
if (function_exists('gd_info')) {
$ver_info = gd_info();
preg_match('/\d/', $ver_info['GD Version'], $match);
$gd_ver = $match[0];
return $match[0];
}
// If phpinfo() is disabled use a specified / fail-safe choice...
if (preg_match('/phpinfo/', ini_get('disable_functions'))) {
if ($user_ver == 2) {
$gd_ver = 2;
return 2;
} else {
$gd_ver = 1;
return 1;
}
}
// ...otherwise use phpinfo().
ob_start();
phpinfo(8);
$info = ob_get_contents();
ob_end_clean();
$info = stristr($info, 'gd version');
preg_match('/\d/', $info, $match);
$gd_ver = $match[0];
return $match[0];
} // End gdVersion()
// Usage:
if ($gdv = gdVersion()) {
if ($gdv >=2) {
echo 'TrueColor functions may be used.';
} else {
echo 'GD version is 1. Avoid the TrueColor functions.';
}
} else {
echo "The GD extension isn't loaded.";
}
?>