basically, i'm making an image using the GD library. it pulls info from a database, and several of the strings can be a variable value.
so, my question is, how would I go about centering the words when the length can change? there must be SOME way to do it, but i'm at a loss on how to.... the script so far is below, and you can see it in action
here
php
<?php
session_start();
$localhost = "XXX";
$mysqlusername = "XXX";
$mysqlpassword = "XXX";
$db = "XXX";
$con = mysql_connect($localhost, $mysqlusername, $mysqlpassword);
mysql_select_db("$db", $con);
$id = $_GET['id'];
$id = htmlspecialchars($id);
$id = mysql_real_escape_string($id);
$sql = mysql_query("SELECT COUNT(*) AS total,id,monster_name,monster_type,monster_level FROM adoptables WHERE id = '$id' GROUP BY id")or die(mysql_error());
$row = mysql_fetch_array($sql);
$monster_type = $row['monster_type'];
$image = imagecreatefromjpeg("images/".$monster_type.".jpg");
$text_type = "tnr.ttf";
$color = imagecolorallocate($image, 255, 255, 255);
$size = 12;
imagettftext($image, $size, 0, 15, 125, $color, $text_type, $row['monster_name']);
imagettftext($image, $size, 0, 15, 140, $color, $text_type, "level ".$row['monster_level']);
header("Content-type: image/jpeg");
imageantialias($image, on);
imagejpeg($image);
imagedestroy($image);
mysql_close($con);
?>
EDIT: I also need a way to check $id and make sure it's an integer.... and once again, i'm not sure how to do it the easy way...
This post has been edited by JBrace1990: 2 Jun, 2008 - 07:29 PM