Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP imagefttext (imagettftext) not displaying anything

I'm almost positive that there is a stupid reason this is not working, but I just can't figure this one out. I'm just trying to print out some text as a graphic with imagettftext, but I can't get the words to display. This is on a GoDaddy server, so I don't control everything, but here are the specs from phpinfo():

  • PHP Version 5.2.14
  • --with-gd' '--with-freetype-dir=/usr' '--with-jpeg-dir=/usr' '--with-png-dir=/usr/bin/libpng-config' '--enable-gd-native-ttf'
  • GD Support enabled
  • GD Version bundled (2.0.34 compatible)
  • FreeType Support enabled
  • FreeType Linkage with freetype
  • FreeType Version 2.2.1

Here is the code I'm using. Nothing fancy or strange.

$width = 270;
$height = 25;
$image = imageCreate($width, $height);
$white = imageColorAllocate($image, 255, 255, 255);
$black = imageColorAllocate($image, 0, 0, 0);
$font = 'verdana.ttf';
imagefttext($image, 16, 0, 0, 0, $black, $font, 'TESTING TEXT');
header("Content-type:  image/gif");
imageGIF($image);

I've tried changing the font name different ways:

$font = './verdana.ttf';
$font = dirname(__FILE__).'/verdana.ttf';

I've tried using PNG instead of GIF, I've tried using imagefttext() and imagettftext(), I've tried displaying errors, but it doesn't show any errors, just a blank screen. Any ideas? It's gotta be something so stupid...

like image 937
SenorPuerco Avatar asked Sep 25 '10 17:09

SenorPuerco


2 Answers

I got it (It hurt my head for a while considering I'm an expert on this...)

The mistake was that the Y position has to have an offeset of the font size so it should look like this

<?php
$width = 270;
$height = 25;
$image = imageCreate($width, $height);
$white = imageColorAllocate($image, 255, 255, 255);
$black = imageColorAllocate($image, 0, 0, 0);
$font = 'verdana.ttf';
imagettftext($image, 16, 0, 0, 16, $black, $font, 'TESTING TEXT');
header("Content-type:  image/gif");
imageGIF($image);
?>
like image 200
Mark Lalor Avatar answered Sep 19 '22 00:09

Mark Lalor


Could it be that you spelled imagettftext wrong?

like image 39
GoalieGuy6 Avatar answered Sep 21 '22 00:09

GoalieGuy6