1

On calling the function imagettfbbox(), I'm getting the error

Fatal error: Uncaught Exception: Function "imagettfbbox" does not exist: check your FreeType installation in...

I understand from many sources, including other stackoverflow questions and PHP manual that I need to compile PHP with freetype support.

My challenge is I do not know exactly how to go about this. Manual says:

To enable support for FreeType 2 add --with-freetype-dir=DIR

Where is this flag to be set?

More importantly, how do I go from my existing set up (detailed following) to this stage?

Set-up (running in a container built off the php7.3.33-apache official image)

  • Apache2 and PHP7.3

  • gd is installed, showing in phpinfo as follows: GD Support enabled/ GD Version bundled (2.1.0 compatible)/ GIF Read Support enabled/ GIF Create Support enabled/ PNG Support enabled/ libPNG Version 1.6.37/ WBMP Support enabled/
    XBM Support enabled

  • /usr/include/freetype2 folder exists and under it, freetype folder and ft2build.h

  • a var_dump of gd_info() yields the following:

    ["GD Version"]=> string(26) "bundled (2.1.0 compatible)" 
    ["FreeType Support"]=> bool(false) 
    ["GIF Read Support"]=> bool(true) 
    ["GIF Create Support"]=> bool(true) 
    ["JPEG Support"]=> bool(false) 
    ["PNG Support"]=> bool(true) 
    ["WBMP Support"]=> bool(true) 
    ["XPM Support"]=> bool(false) 
    ["XBM Support"]=> bool(true) 
    ["WebP Support"]=> bool(false) 
    ["BMP Support"]=> bool(true) 
    ["JIS-mapped Japanese Font Support"]=> bool(false) 
    

In essence, my PHP is pre-compiled. How do I replace this with my own re-compilation as the manual seems to be saying.

user1729972
  • 712
  • 2
  • 9
  • 29

1 Answers1

0

The problems are known but they do not provide a satisfactory solution for both mine and your cases:

[1] freetype-config issues in Ubuntu 20.04: https://github.com/mapnik/mapnik/issues/4152

[2] gd issues with php-7.3 and Ubuntu 20.04:
https://github.com/docker-library/php/issues/865#issuecomment-511163936

If you're running PHP with Docker, the link [2] provides an elegant solution to this problem, which I believe is the best one.

However, given your perplexities, the previously mentioned thread is not suited to your situation.

I've found a solution:

  1. Obtain a copy of freetype-config from the provided link: https://gist.github.com/kaisersource/77ecb5979e05bd51c7f4994b8f99337d

  2. Copy the script in a directory that contains executable programs e.g. /usr/local/bin

  3. Download the PHP 7.3 source code from the official website https://www.php.net/distributions/php-7.3.33.tar.bz2 and compile it from source.

  4. Unzip the package and navigate to the folder that contains the source code

  5. Configure the build by running the following command: ./configure [your additional flags] --with-freetype-dir=/usr/include/freetype2 The directory may vary depending on the operating system

  6. Compile the source code by running the following command: make

  7. Install PHP 7.3 by running the following command: make install

This workaround should work for php versions lower than 7.3 as well. I have also tested with php 7.2.

For versions higher than php 7.4 there shouldn't be issues as it relies on pkg-config, as you can see from the manual

https://www.php.net/manual/en/image.installation.php

Hope it helps