Skip to Content

My Little Pet Dragon

My Little Pet Dragon by S.E. Gordon

Just $1.99 for your Kindle

Subscribe now to get the latest updates from S.E. Gordon

Now Available!

Literary Dynamite by S.E. Gordon

Now available on Amazon, Apple, Barnes & Noble, Kobo, Smashwords, Lulu, Scribd and Tradebit

Literary Dynamite

Literary Dynamite by S.E. Gordon

Just 99 cents for your Kindle or Nook!

Useful Resources


Home > Graphical Programming Using GD > Verifying GD

Verifying GD

There are three simple ways to detect the presence of GD, and if so, the associated version. The best way is to review the results of phpinfo().

To do this, create a new document called phpinfo.php and include the following:

<?php phpinfo(); ?>

Save this file, upload it to the server, then navigate to it. Save off the resulting HTML file then delete phpinfo.php from the server. If this information winds up in the wrong hands, it could easily be used to compromise the server.

Scroll down to the section titled “gd.” It should look something like this:


GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

At a glance one can validate a variety of information about GD, including its support of GIF, JPG, and PNG. Also note that the current build is "compatible with 2.0.28," but doesn't specify the exact version.

The second and third methods embed code directly into a PHP document.

PHP includes the function gd_info() that gathers data found in phpinfo() and returns it in an associative array, as follows:

array(11) {
  ["GD Version"]=>
  string(27) "bundled (2.0.28 compatible)"
  ["FreeType Support"]=>
  ["FreeType Linkage"]=>
  string(13) "with freetype"
  ["T1Lib Support"]=>
  ["GIF Read Support"]=>
  ["GIF Create Support"]=>
  ["JPG Support"]=>
  ["PNG Support"]=>
  ["WBMP Support"]=>
  ["XBM Support"]=>
  ["JIS-mapped Japanese Font Support"]=>

To verify the existence of the GD library, one can also check to see if the extension has been loaded.


 if ( !extension_loaded ( gd ) )
    die ( "The GD library is not installed.\n" );

Which could also be written as:

   if ( !extension_loaded ( gd ) ) {

      echo "The GD library is not installed\n";

      /* Add to error log */

      exit( 0 );


The associated DLL or socket can also be validated as follows:

   if ( !extension_loaded ( gd ) ) {

      if ( !dl( '' ) ) {

         echo "The GD library is not installed\n";
         exit( 0 );



The extension_loaded() function returns a boolean value; 1 if GD is installed, 0 if not. At first it might not seem particularly useful, but it can be used to dynamically detect a module, ensuring interoperability and portability from one system to the next.

To see all of the possible parameters for extension_loaded(), use get_loaded_extensions(). An array will be returned with every module installed.

Here's a simple function that summarizes the results:


   function display_loaded_modules() {

      echo "<p><strong>Loaded Modules</strong></p>\n\n";

      // Get extensions

      $this_array = get_loaded_extensions();

      sort ( $this_array );

      // Display extensions

      echo "<ul>\n";

      foreach ( $this_array as $value ) {

         echo "   <li>$value</li>\n";


      echo "</ul>\n\n";



--S.E. Gordon

Additional Information