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

  1. <?php
  2. /**
  3. * Get which version of GD is installed, if any.
  4. *
  5. * Returns the version (1 or 2) of the GD extension.
  6. */
  7. function gdVersion($user_ver = 0)
  8. {
  9. if (! extension_loaded('gd')) { return; }
  10. static $gd_ver = 0;
  11. // Just accept the specified setting if it's 1.
  12. if ($user_ver == 1) { $gd_ver = 1; return 1; }
  13. // Use the static variable if function was called previously.
  14. if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; }
  15. // Use the gd_info() function if possible.
  16. if (function_exists('gd_info')) {
  17. $ver_info = gd_info();
  18. preg_match('/\d/', $ver_info['GD Version'], $match);
  19. $gd_ver = $match[0];
  20. return $match[0];
  21. }
  22. // If phpinfo() is disabled use a specified / fail-safe choice...
  23. if (preg_match('/phpinfo/', ini_get('disable_functions'))) {
  24. if ($user_ver == 2) {
  25. $gd_ver = 2;
  26. return 2;
  27. } else {
  28. $gd_ver = 1;
  29. return 1;
  30. }
  31. }
  32. // ...otherwise use phpinfo().
  33. ob_start();
  34. phpinfo(8);
  35. $info = ob_get_contents();
  36. ob_end_clean();
  37. $info = stristr($info, 'gd version');
  38. preg_match('/\d/', $info, $match);
  39. $gd_ver = $match[0];
  40. return $match[0];
  41. } // End gdVersion()
  42. // Usage:
  43. if ($gdv = gdVersion()) {
  44. if ($gdv >=2) {
  45. echo 'TrueColor functions may be used.';
  46. } else {
  47. echo 'GD version is 1. Avoid the TrueColor functions.';
  48. }
  49. } else {
  50. echo "The GD extension isn't loaded.";
  51. }
  52. ?>