Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,683 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,236 people online right now. Registration is fast and FREE... Join Now!




GD text center

 
Reply to this topicStart new topic

GD text center

JBrace1990
post 2 Jun, 2008 - 07:27 PM
Post #1


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 474



Thanked 21 times

Dream Kudos: 350
My Contributions


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
User is offlineProfile CardPM

Go to the top of the page

silverblaze
post 2 Jun, 2008 - 07:44 PM
Post #2


D.I.C Head

**
Joined: 18 Jan, 2008
Posts: 51



Thanked 3 times
My Contributions


For centering the text in a image hope this will help you out.
http://www.retireat21.com/tutorial/52 ... I got this from google smile.gif but when i tried it .. it worked smile.gif ...

For checking whether $id is an integer you can use the function is_int .

hope this will help....


take care..

This post has been edited by silverblaze: 2 Jun, 2008 - 07:46 PM
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 3 Jun, 2008 - 04:04 PM
Post #3


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 474



Thanked 21 times

Dream Kudos: 350
My Contributions


thank you, that got it working perfectly.... here's the final product:
IPB Image
User is offlineProfile CardPM

Go to the top of the page

silverblaze
post 5 Jun, 2008 - 08:42 AM
Post #4


D.I.C Head

**
Joined: 18 Jan, 2008
Posts: 51



Thanked 3 times
My Contributions


I am glad i culd help...

take care..
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:55AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month