I'm creating a gif using php and gd library. I'm developing on Windows XP with a local installation of Apache and PHP 4.3.11. The gif is created exactly as expected. But when I upload to my webhost (Linux, PHP 4.3.11) the text is left aligned! It's as if the fourth parameter of imagettftext is being ignored for some bizarre reason.

Here's a screenshot of the result on my Windows PC:

[screenshot]

And here's a screenshot of the result on my LAMP-based webhost.

[screenshot]

Anyone got any ideas?

Here's the PHP code:

<?php

header("Content-type: image/gif");

$image = imagecreatefromgif("imgs/heading_boilerplate.gif");

$line1_text = $_GET['line1'];
$line1_color = imagecolorallocate($image, 0, 0, 0); //black
$line1_x = 44;
$line1_y = 37;
$line1_size = 24;
$line1_font = './fonts/georgia.ttf';

$line2_text = $_GET['line2'];
$line2_color = imagecolorallocate($image, 66, 66, 66); //grey
$line2_x = 126;
$line2_y = 59;
$line2_size = 16;
$line2_font = './fonts/georgia.ttf';

imagettftext($image, $line1_size, 0, $line1_x, $line1_y, $line1_color, $line1_font, $line1_text);
imagettftext($image, $line2_size, 0, $line2_x, $line2_y, $line2_color, $line2_font, $line2_text);

imagegif($image);
imagedestroy($image);

?>

    oehm....
    compare output of phpinfo() on both maschines

      quicknik wrote:

      oehm....
      compare output of phpinfo() on both maschines

      I can't see anything relevant. The versions of PHP, Apache and GD appear to be the same, yet the problem only occurs on LAMP. Here's some miscellany from phpinfo:

      My PC (Win XP Home):

      PHP Version 4.3.11
      Apache Version: Apache/1.3.33 (Win32) PHP/4.3.11
      Thread Safety: enabled
      Registered PHP Streams php, http, ftp, compress.zlib
      GD Support: enabled
      GD Version: bundled (2.0.28 compatible)
      FreeType Support: enabled
      FreeType Linkage: with freetype
      GIF Read Support: enabled
      GIF Create Support: enabled
      JPG Support: enabled
      PNG Support: enabled
      WBMP Support: enabled
      XBM Support: enabled

      My webhost (LAMP):

      PHP Version: 4.3.11
      SERVER_SOFTWARE: Apache/1.3.33 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7a PHP-CGI/0.1b
      Thread Safety: disabled
      Registered PHP Streams: php, http, ftp, https, ftps, compress.zlib
      GD Support: enabled
      GD Version: bundled (2.0.28 compatible)
      FreeType Support: enabled
      FreeType Linkage: with freetype
      GIF Read Support: enabled
      GIF Create Support: enabled
      JPG Support: enabled
      PNG Support: enabled
      WBMP Support: enabled
      XBM Support: enabled

        Hi,

        hmmm compare freetype versions....
        bye,
        nikolas

          I dont know how to check freetype versions, but it clearly appears to be a bug in my webhost's installation of gd/freetype or a config issue. If anyone else has any ideas I'd be grateful.

            I grabbed some example PHP code off another php website which created a png image with text, and the issue was still there on my webhost (again, fine on my setup). The only other thing I could think of was the font itself - maybe Linux doesnt like it. I tried to obtain VOLT to recompile my test fonts but Microsoft make it hard to get.

              regarding the font, I downloaded a free TTF font from sourceforge and still have the problem (i.e. fine on my PC, but no x-positioning on webhost). I'm now out of ideas so I'll email my hosting provider.

                I just tried the very similar imagefttext function too. Exactly the same problem - fine on my PC but ignores X-coordinate on my webhost!

                My webhost has just replied to my email with the following information:

                freetype-2.1.9-1
                freetype-devel-2.1.9-1
                gd-2.0.28-4
                gd-progs-2.0.28-4
                gd-devel-2.0.28-4

                And according to them they're the latest versions.

                Anyone got any ideas?

                If anyone who is using imagettftext or imagefttext successfully on a Linux server could you send me a private message with the exact font you're using? This would allow me to rule the font file out of the equation!

                  Write a Reply...