PDA

View Full Version : gd fontsize


rafiki
10-20-2006, 01:51 AM
<?php
$text = $_GET['text'];
$im = @imagecreate(150, 50) or die("Cannot Create new GD image");
$bc = imagecolorallocate($im, 0, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
header("Content-type: image/png");
imagestring($im, 16, 16, 16, $text, $tc);
imagepng($im);
imagedestroy($im);
?>
which part do i change for the font size?
also how can i change the font of the txt in the image?
thanks
Rafiki

SeeIT Solutions
10-20-2006, 06:09 AM
http://php.net/manual/en/function.imagestring.php


Also check out... http://www.php.net/manual/en/function.imageloadfont.php

rafiki
10-20-2006, 11:41 AM
thanks seeit i read it last nite mustve been 2 tired 2 understand it :)

rafiki
10-20-2006, 12:04 PM
still doesnt seem 2 work
<?php
$text = $_GET['text'];
$font = "/TURNB___.TTF" or die("Font loading failed");
$im = @imagecreate(150, 50) or die("Cannot Initialize new GD image stream");
$bc = imagecolorallocate($im, 0, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
header("Content-Type : Image/PNG");
imagestring($im, $font, 16, 16, $text, $tc);
imagepng($im);
imagedestroy($im);
?>

or
<?php
$text = $_GET['text'];
$font = imageloadfont("TURNB___.TTF") or die("Font loading failed");
$im = @imagecreate(150, 50) or die("Cannot Initialize new GD image stream");
$bc = imagecolorallocate($im, 0, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
header("Content-Type : Image/PNG");
imagestring($im, $font, 16, 16, $text, $tc);
imagepng($im);
imagedestroy($im);
?>
any ideas?

SeeIT Solutions
10-21-2006, 08:57 AM
<?php

// image text
$text = $_GET['text'];

// make sure it doesn't cache
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-type: image/png");

// get size of string to make image correct size
$size = imagettfbbox(8,0,"arial.ttf",$content);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);

//make image
$im = imagecreate($dx,$dy);

//create the background image and font color
$bg = imagecreatefromgif('bg.gif');
$black = imagecolorallocate($im,0,0,0);

//put the background image in the correct size image
imagecopy($im,$bg,0,0,0,0,$dx,$dy);

//write text with arial font (file is in same directory as this script)
imagettftext($im, 8, 0, 0, $dy, $black, "arial.ttf", $text);

//show image
imagepng($im);
imagedestroy($im);

?>

That is a script I use, play with it a bit.

Good luck.