Detect if the FreeType PHP extension is installed on the server

Asked
Active3 hr before
Viewed126 times

8 Answers

serverdetect
90%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,How do I test to see if the FreeType extension is installed on a server running PHP? ,Assuming the GD library is installed, you can detect Freetype support using the gd_info() function.,I wanted to make a simple CAPTCHA system on my site, so I used imagettftext() and it worked fine. But what if the server didn't have the FreeType library installed?

if (function_exists('imagettftext')) {
   imagettftext();
} else {
   // do other function
}
load more v
88%

How do I test to see if the FreeType extension is installed on a server running PHP? ,I wanted to make a simple CAPTCHA system on my site, so I used imagettftext() and it worked fine. But what if the server didn't have the FreeType library installed?,You are not using any of these two. Instead use the Extension Loading Directives and you're fine.,So is there a way to somehow detect FreeType library through code, and if it is not present, fall back to something like imagestring()?

Use function_exists:

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

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.,If you need to check whether or not GD library is installed first, use extension_loaded('gd');,Assuming the GD library is installed, you can detect Freetype support using the gd_info() function.

Use function_exists:

if (function_exists('imagettftext')) {
   imagettftext();
} else {
   // do other function
}
load more v
65%

extension_loaded — Find out whether an extension is loaded, You can see the names of various extensions by using phpinfo() or if you're using the CGI or CLI version of PHP you can use the -m switch to list all available extensions: , Finds out whether the extension is loaded. , Returns true if the extension identified by extension is loaded, false otherwise.

$ php - m[PHP Modules]
xml
tokenizer
standard
sockets
session
posix
pcre
overload
mysql
mbstring
ctype

   [Zend Modules]
75%

However, enabling Freetype libraries on the server involves a series of steps.,At Bobcares, we receive requests to enable PHP FreeType support on the server as a part of our Server Management Services.,Initially, we use the below command to install FreeType on a CentOS server.,Today, let’s see how our Support Engineers install the FreeType support and fix related errors.

Initially, we use the below command to install FreeType on a CentOS server.

yum install freetype
load more v
40%

#install gd extension, 7.4 replace it with your version
sudo apt - get install php7 .4 - gd
#check
if installed
php - m | grep gd
#restart your web server
sudo service apache2 restart
or
sudo service nginx restart
load more v
22%

This guide will show you how to get started with LSPHP (PHP with LiteSpeed API) on your *nix machine using different methods depending on your operating system, how to compile PHP from Source, and how to install LSPHP on your Control Panel environments. It will then show you how to configure LSPHP with LiteSpeed Web Server.,To have the changes you have just made to /usr/local/lsws/conf/httpd_config.xml take effect inside of LiteSpeed Web Server run the following: ,Now that the dependencies have been installed you can work on compiling PHP. ,Setting up PHP on LiteSpeed Web Server is simple with the induction of the PHP section starting in LSWS version 5.3. For control panel environments the PHP is auto detected and if needed can be overridden on a per setup basis. This setup will show you how to manually setup the PHP section to work with the binaries on your system to serve PHP files.

$ sudo yum install http: //rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el6.noarch.rpm
   $ sudo yum install https: //rpms.remirepo.net/enterprise/remi-release-6.rpm
   $ sudo yum install epel - release
load more v
60%

Fig. 01: Indicating PHP GD module ini file loaded on Ubuntu for Apache (click to enlarge),Fig.02 GD is enabled on my Ubuntu 20.04 LTS for Apache (click to enlarge),You can type php -m command to see php-gd support is loaded or not at a shell prompt: php -m,You learned how to install php-gd support for Apache web server under Ubuntu Linux.

The syntax is as follows for the apt-cache command and pipe output using grep command:
apt-cache search php | grep
Here is what I see on Ubuntu 20.04 LTS:

php - gd - GD module
for PHP[
   default]
php7 .4 - gd - GD module
for PHP
Reading package lists...Done
Building dependency tree
Reading state information...Done
The following extra packages will be installed:
   libgd2 - xpm
Suggested packages:
   libgd - tools
The following packages will be REMOVED:
   libgd2 - noxpm
The following NEW packages will be installed:
   libgd2 - xpm php5 - gd
0 upgraded, 2 newly installed, 1 to remove and 7 not upgraded.
Need to get 270 kB of archives.
After this operation, 176 kB of additional disk space will be used.
Do you want to
continue [Y / n] ? y
Get: 1 http: //debian.osuosl.org/debian/ squeeze/main libgd2-xpm amd64 2.0.36~rc1~dfsg-5 [231 kB]
   Get: 2 http: //security.debian.org/ squeeze/updates/main php5-gd amd64 5.3.3-7+squeeze9 [39.1 kB]
   Fetched 270 kB in 2 s(124 kB / s)
dpkg: libgd2 - noxpm: dependency problems, but removing anyway as you requested:
   libgvc5 depends on libgd2 - noxpm( >= 2.0 .36~rc1~dfsg) | libgd2 - xpm( >= 2.0 .36~rc1~dfsg);
however:
   Package libgd2 - noxpm is to be removed.
Package libgd2 - xpm is not installed.
   (Reading database...206928 files and directories currently installed.)
Removing libgd2 - noxpm...
   Selecting previously deselected package libgd2 - xpm.
   (Reading database...206919 files and directories currently installed.)
Unpacking libgd2 - xpm(from.../libgd2-xpm_2.0.36~rc1~dfsg-5_amd64.deb) ...
      Setting up libgd2 - xpm(2.0 .36~rc1~dfsg - 5)...
      Selecting previously deselected package php5 - gd.
      (Reading database...206930 files and directories currently installed.) Unpacking php5 - gd(from.../php5-gd_5.3.3-7+squeeze9_amd64.deb) ...
         Processing triggers
         for libapache2 - mod - php5...
         Reloading web server config: apache2.Setting up php5 - gd(5.3 .3 - 7 + squeeze9)...

Type the following command at a shell prompt:
$ php5 -m | grep -i gd # older version
# OR for the latest version try
$ php -m | grep gd

Sample outputs:

gd
gd
GD Support => enabled
GD headers Version => 2.2 .5
GD library Version => 2.2 .5
gd.jpeg_ignore_warning => 1 => 1
< ? php
phpinfo(); ?
>
load more v