Freetype support in PHP

Posted on 2006-06-06
Last Modified: 2013-12-13
My web server used to support GD and Freetype with PHP. Now, after an upgrade, scripts that use GD still work, but not scripts that use freetype functions like imageFTText(). When I reinstalled PHP, I didn't compile it with freetype support. I reinstalled with these configure option:
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-oci8=/home/oracle/product/9.2.0 --with-jpeg-dir=/usr --with-png-dir=/usr --with-gd --with-zlib --with-oracle=/home/oracle/product/9.2.0 --with-zlib --with-ttf=/usr --with-freetype-dir=/usr
Then I ran "make" and "make install" and restarted Apache. I didn't get any error messages, but when I tried to run the PHP script that calls imageFTText(), I got the same error. I've also tried configuring without "--with-ttf", without "--with-freetype-dir", and using "/usr/lib" instead of "/usr", but with the same results. phpinfo() shows that the PHP installation is being updated.

The server runs Apache 2.2, PHP 5.1.2 on Red Hat Enterprise Linux 4 AS. gd-2.0.28-4.4E.1, gd-devel-2.0.28-4.4E.1, freetype-2.1.9-1, freetype-devel-2.1.9-1, and freetype-utils-2.1.9-1 are installed from the default Red Hat RPMs. /usr/lib contains:
-rw-r--r--  1 root root 491356 Aug  4  2004 /usr/lib/libfreetype.a
-rwxr-xr-x  1 root root    816 Aug  4  2004 /usr/lib/
lrwxrwxrwx  1 root root     20 Jun  6 17:41 /usr/lib/ ->
lrwxrwxrwx  1 root root     20 Apr  5 16:02 /usr/lib/ ->
-rwxr-xr-x  1 root root 424068 Aug  4  2004 /usr/lib/
-rw-r--r--  1 root root 255212 Jan 20 04:48 /usr/lib/libgd.a
-rwxr-xr-x  1 root root 229904 Jan 20 04:48 /usr/lib/

Please help!
Question by:abalonia
    LVL 40

    Expert Comment

    POI - Freetype 1.x  has been removed in PHP6

    From the PHP Manual (which seems to match what you are doing) ...

    Enhance the capabilities of GD to deal with different fonts by specifying the --with-XXXX configure switch to your PHP configure line.

    FreeType 1.x        To enable support for FreeType 1.x add --with-ttf[=DIR].  
    FreeType 2          To enable support for FreeType 2 add --with-freetype-dir=DIR.  
    T1lib                   To enable support for T1lib (Type 1 fonts) add --with-t1lib[=DIR].  
    Native TrueType string function            To enable support for native TrueType string function add --enable-gd-native-ttf.  

    Can you create a script gdinfo.php

    <?php print_r(gdinfo()); ?>

    I'm on windows and I get ...

    array (
      'GD Version' => 'bundled (2.0.28 compatible)',
      'FreeType Support' => true,
      'FreeType Linkage' => 'with freetype',
      'T1Lib Support' => true,
      'GIF Read Support' => true,
      'GIF Create Support' => true,
      'JPG Support' => true,
      'PNG Support' => true,
      'WBMP Support' => true,
      'XPM Support' => false,
      'XBM Support' => true,
      'JIS-mapped Japanese Font Support' => false,

    Which is also reflected in phpinfo().

    If you get similar output to me, it suggests that everything is OK with PHP.

    My php.ini only has ext=php_gd2.dll activated.

    So - what is the version of GD you are getting back?

    From the PHP Manual for imagefttext() ...

    This function requires GD 2.0.1 or later (2.0.28 or later is recommended).

    You say you have /usr/lib/ I'm not a *ix bod, but I suspect that this is the issue.

    You need 2.0.1 at least.

    LVL 1

    Author Comment

    I actually have GD 2.0.28 installed. I just tried downloading and installing GD 2.0.33 from source into /usr/local/lib. I can't uninstall the GD 2.0.28 rpm because too many other applications depend on it, plus I don't want to mess up Redhat's RPM update. I backed up the old GD libraries and include files, then copied the new libraries and include files from /usr/local/lib and /usr/local/include to /usr/lib and /usr/include. I recompiled PHP with and with "--with-freetype-dir=/usr" and both with and without "--with-ttf=/usr" and "--enable-gd-native-ttf", but imageFTText() still doesn't work. phpinfo displays the following for gd:
    GD Support       enabled
    GD Version       bundled (2.0.28 compatible)
    GIF Read Support       enabled
    GIF Create Support       enabled
    JPG Support       enabled
    PNG Support       enabled
    WBMP Support       enabled
    XBM Support       enabled

    I guess it doesn't know that GD was upgraded? gdinfo() doesn't work for me.
    LVL 40

    Expert Comment


    How about putting the new libraries somewhere else and then using that location to the recompile?





    Typo. Sorry.

    From the PHP Manual ...

    Returns an associative array describing the version and capabilities of the installed GD library.

    Table 118. Elements of array returned by gd_info()
    Attribute Meaning
    GD Version string value describing the installed libgd version.
    Freetype Support boolean value. TRUE if Freetype Support is installed.
    Freetype Linkage string value describing the way in which Freetype was linked. Expected values are: 'with freetype', 'with TTF library', and 'with unknown library'. This element will only be defined if Freetype Support evaluated to TRUE.
    T1Lib Support boolean value. TRUE if T1Lib support is included.
    GIF Read Support boolean value. TRUE if support for reading GIF images is included.
    GIF Create Support boolean value. TRUE if support for creating GIF images is included.
    JPG Support boolean value. TRUE if JPG support is included.
    PNG Support boolean value. TRUE if PNG support is included.
    WBMP Support boolean value. TRUE if WBMP support is included.
    XBM Support boolean value. TRUE if XBM support is included.
    LVL 40

    Expert Comment

    I'm on Windows, so I'm pretty much stuck now.
    LVL 1

    Author Comment

    I got gd_info() working, and it doesn't show freetype support. I did try compiling PHP with the new GD libraries in /usr/local, but got a bunch of errors.
    LVL 40

    Accepted Solution

    I'm not really able to think of anything more than maybe deleting PHP and the libraries and starting again.

    Is it possible to install PHP and the libraries into a completely different structure and use completely different paths to the normal ones?

    LVL 1

    Author Comment

    I got GD and Freetype working after I recompiled PHP with the new version of the GD libraries that I installed in /usr/local, which is a different directory tree. The previous attempt failed because I didn't do a "make clean" before compiling.
    LVL 40

    Expert Comment

    Ah. The whole "having to recompile program to run" on Linux is probably (for a Windows user) one of the major issues I have.

    I just download and install. Edit an INI file and restart webserver. Done!

    BUT, I am always behind the releases (unless I use the snapshots).

    Swings and roundabouts.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to dynamically set the form action using jQuery.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now