Detect if the FreeType PHP extension is installed on the server

↘锁芯ラ 提交于 2019-12-01 15:14:51
Norm

Use function_exists:

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

Hope that helps.

Jon

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');

A first somewhat complicated approach:

call php_info() and search/parse the result for freetype

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.

Try function_exists(), i.e.

if (!function_exists('imagettftext')) {
  // No freetype library
}

You'd probably be best asking for alternatives to imagettftext as a separate question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!