Search code examples
phpglyphimagettftext

PHP: imagettftext stops when it reaches a space


http://ttgdark.com/plugins/xboximg.php?gamertag=testing...

http://ttgdark.com/plugins/xboximg.php?gamertag=another test

If you note, the second link does not write the word "test". I just decided to start learning about dynamic image writing today, and I really don't know where to start on figuring out what's wrong. Here is my code:

<?php

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

    $font = 'micross.ttf';
    $image = @imagecreatefrompng( 'test.png' );
    $white = @imagecolorallocate( $image, 255, 255, 255 );
    $grey = @imagecolorallocate( $image, 128, 128, 128 );
    $black = @imagecolorallocate( $image, 0, 0, 0 );

    $text = $_GET['gamertag'];
      //$text = urlencode( $text ); // Replaces spaces with plus signs
    @imagettftext( $image, 11, 0, 40, 50, $black, $font, $text );
    @imagepng( $image );
    @imagedestroy( $image );

?>

PHP Warning: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Problem rendering glyph in /var/www/vhosts/ttgdark.com/httpdocs/plugins/xboximg.php on line 12


Solution

  • Then there is something about the space that imagettftext() doesn't like. Maybe it doesn't like your font or encoding? Try a different font and see what happens.