I was making a module the other day that had some dependencies on PEAR and GD. So I cobbled together a test for GD and PEAR from some GPL‘d code I found online. I thought that I’d share the code snips (it is all GPL licensed code by the way).

PEAR
The PHP Extension and Application Repository is a standard library of reusable PHP components.
GD
The GD library is an image manipulation library that can be used with PHP

Checking for GD in PHP

/**
 * check if GD is installed and is version 2 or higher
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
if (! extension_loaded('gd')) {
    echo "The GD extension was not found!";
} else {
    if (function_exists('gd_info')) {
        // use gd_info if possible...
        $gd_ver_info = gd_info();
        preg_match('/\d/', $gd_ver_info['GD Version'], $match);
        if ($match[0] < 2) {
            echo "This program needs GD version 2 or higher to run properly.";
        }
    } else {
        // ...otherwise use phpinfo().
        ob_start();
        phpinfo(8);
        $info = ob_get_contents();
        ob_end_clean();
        $info = stristr($info, 'gd version');
        preg_match('/\d/', $info, $match);
        if ($match[0] < 2) {
            echo "This module requires the GD Library version 2 or higher.";
        }
    }
}

Checking for PEAR in PHP

/**
 * check if PEAR is installed
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
if (!class_exists('PEAR') || !(@include 'PEAR.php')) {
	echo "This module requires the PEAR Library.";
}