-
[php] Text in Images
Hi,
I've created a small script which creates an image with some text on. I can change a few things on this image, but not the font of the text in it, or the font size. Now, just to clarify, I want the font to be one loaded in from a .ttf file in the directory that my php file is in; I'm using arial.ttf as a test.
Here's my code so far:
Code:
<?php
// Recieve vars and up them into variables
$t = $_GET['text']; // Text string
$h = $_GET['height']; // Height of background
$w = $_GET['width']; // Width of background
$x = $_GET['x']; // X position of text
$y = $_GET['y']; // Y position of text
// Create an image at the size defined in the vars
$im = @imagecreate($w, $h);
// Set background colour to green
$bc = imagecolorallocate($im, 0, 255, 0);
// Set text colour to red
$tc = imagecolorallocate($im, 255, 0, 0);
// Write the text string into an image
// (resource image, font, x, y, string, text colour)
imagestring($im, 5, $x, $y, $t, $tc);
// Output Image
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
You can see the results of this here
Thanks for any help. ;)
-
Hi,
go to www.php.net and read about imageloadfont and imagepsloadfont
Musicman
-
OK, thanks for that.
I didn't use either of those in the end, instead I found "imagettftext" which someone had referenced in the comments on imageloadfont (I think it was that one).
It now works great with a whole 2 fonts that I've uploaded. ;)