Detect if the FreeType PHP extension is installed on the server

Use function_exists:

if (function_exists('imagettftext')) {
     imagettftext();
} else {
     // do other function
}

Hope that helps.


This won't work for dynamic code (so not a true answer to the question) but for anyone who just want's to know if it's installed, from the command line on Linux:

php -i | grep -E "GD|FreeType"

Outputs:

GD Support => enabled
GD headers Version => 2.2.5
GD library Version => 2.2.5
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.4.11

NOTE: On a system without it installed you'll get no output.


This will not be better in practice than the function_exists solutions already posted, but the technically correct way to check is by using extension_loaded.


Assuming the GD library is installed, you can detect Freetype support using the gd_info() function.

$gdinfo = gd_info();
if($gdinfo['FreeType Support']) echo 'FreeType Support Enabled';

If you need to check whether or not GD library is installed first, use extension_loaded('gd');