Re: Writing text into images, and setting text size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, December 16, 2007 7:59 pm, Dave M G wrote:
> I've been able to write text into an image using the default fonts
> available, with this command:
>
> ImageString($image, 5, $x - 20,$y-10, $text, $textColour);
>
> The problem is that the font that is identified by the index "5" is
> too
> small. But it seems that it can't be scaled in any way.

Have you tried 0, 1, 2, 3 and 4?

They are all built-in and different sizes.

> So I thought I would try to specify a font and try something like
> this:
>
> $font = '/usr/share/fonts/truetype/freefonts/FreeSans.ttf';
> $imagettftext($image, 20, 0, $x, $y-10, $textColour, $font, $text);
>
> But I'm clearly not doing things quite right, and I have some
> questions:
>
> 1. 'FreeSans.ttf' is in my /usr/share/fonts/truetype/freefonts
> directory. But specifying it doesn't seem to work. How do I get the
> system to find the font?

This should work, according to the docs...

Can the FreeSans.ttf file be read by the PHP user?

> 2. I need the scripts I'm writing to be portable, so can I be sure of
> what fonts will be available, and will I be able to locate them?

You are plain out of luck here.
There is NOTHING you can rely on for fonts installed at all, much less
where they will be.
You'd have to package them in with your own software to be safe.

And that may open up licensing/legal issues...

> 3. I'm not really concerned about what font it is, just that it's
> large
> and readable. If there are other options than what I've explored here,
> then I would be open to those too.

You could draw the image with a smaller font, and scale the whole
image up...

But that would usually not work well, as the scaling up has to
interpolate pixels, which rarely looks good...

You could also try using:
$font =
imageloadfont('/usr/share/fonts/truetype/freefonts/FreeSans.ttf');
if (!$font){
  error_log("Unable to load font!");
  $font = 5; //fall back to built-in font #5
}
ImageString($image, $font, $x - 20,$y-10, $text, $textColour);

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux