You are not logged in.

#1 2007-10-31 19:48:10

Bogart
Member
From: Madrid, Spain
Registered: 2005-06-22
Posts: 272

Can't create text with PHP using imagettftext [SOLVED]

I think that after the upgrade of PHP to the modular one I can't create text using TTF fonts. Before I file a bug report could someone confirm if it works or not for them? I might just have screwed something in my box.

This code should create a text image and display it in the browser (it assumes you have DejaVu fonts in the default directory):

<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = '/usr/share/fonts/TTF/DejaVuSans.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

Could someone with an up to date php with GD enabled tell me if it works or him/her?

Thanks.

EDIT: Ok, I solved it. The error reporting is turned off by default now, so I was not getting any error. After turning it on I found out it was related to the open_basedir directive being enabled now in php.ini. Turning it off allowed me to access the TTF for drawing text.

Last edited by Bogart (2007-11-01 00:43:33)

Offline

Board footer

Powered by FluxBB