Jump to content


Photo

Problem creating image with text


  • Please log in to reply
5 replies to this topic

#1 Han

Han

    Newbie

  • Member
  • Pip
  • 3 posts
  • Main OS: Windows XP

Posted 09 July 2008 - 09:48 AM

The following script works with Uniserver3_2a, but fails with Uniserver3_5
Error messages says that the font file is missing.
Where can I get a font file and what is the location I have to put it?

Thanks,
Han

++++++++++++++++++++++++++++
function vertText($text, $id)
{
// Create the image
$im = imagecreatetruecolor(20, 80);

$background = imagecolorallocate($im, 253, 208, 23);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 19, 79, $background);

$font = 'arial.ttf';

// Add the text
imagettftext($im, 12, 270, 5, 5, $black, $font, $text);

// Create the image with vertical text
imagepng($im, "$id.png");
imagedestroy($im);
}

#2 Ric

Ric

    Project Manager

  • Admin
  • PipPipPipPipPip
  • 1,535 posts
  • Gender:Male
  • Location:Cambridge,UK
  • Interests:Electronics
    Internet in general
    Open source projects
  • SourceForge IDmpgcan
  • Wiki ID: Ric
  • Main OS: Windows XP

Posted 09 July 2008 - 12:42 PM

You need to supply a path for the font.

If using this : $font = 'arial.ttf'; copy the font to the folder where your script is located.

Alternatively change the line to $font = 'C:\WINDOWS\Fonts\arial.ttf';

All the best
Ric :)

#3 Han

Han

    Newbie

  • Member
  • Pip
  • 3 posts
  • Main OS: Windows XP

Posted 09 July 2008 - 05:32 PM

Putting a copy of the arial.ttf from c:\windows\fonts in the scripts folder has the effect of not showing an error message. But the created image contains no text.
Any explanation why uniserver3_2a does not need a font file in the script folder?
I searched php.ini for a font directory, I searched the uniserver3_2a directory tree for font files, but I found nothing. Where is 3_2a getting the font definition? Is 3_5 doing things differently?
Thanks,
Han

#4 jacob lee

jacob lee

    Junior Member

  • Member
  • Pip
  • 20 posts

Posted 09 July 2008 - 08:44 PM

As RIC said, the only thing you need is
$font = 'C:\WINDOWS\Fonts\arial.ttf';
and copying the font to your script is not need.

works fine. tested with the fresh uniformserver 3.5.

ps: if you have the png file already please delete it first and test again.

#5 nicFranck

nicFranck

    Newbie

  • Member
  • Pip
  • 1 posts
  • Main OS: Windows XP

Posted 27 May 2009 - 10:57 AM

Hi there,

The problem is that the var $FontName (or $this->FontName) of the pChart-class is initiated as NULL. Unless you change that value by using setFontProperties, this NULL is used as the path to that ttf-file.

So please set this by using for example:
$mychart->setFontProperties("Fonts/pf_arma_five.ttf",12).

It worked for me

O I'm sorry, I tought that this was about pChart, because it also uses imageftbbox. I just couldn't delete this answer. So don't mind.

#6 Ashley

Ashley

    Junior Member

  • Member
  • Pip
  • 20 posts
  • Main OS: Windows Vista

Posted 17 May 2010 - 04:24 PM

Hi,
First of all,you copy the font where your script is situated.





_______________________________
"Want to get-on Google's first page in 48 hours and flood your site with traffic?
Try Traffic Geyser, the internet's #1 video marketing software at Traffic Geyser "




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users