Jump to content


Photo

Image out put error


  • Please log in to reply
No replies to this topic

#1 Tatara

Tatara
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 14 August 2006 - 05:41 PM

ok i wrote a script with the help of ppl here to do a quest bar it connects to a sql database but it outputting the image wrong it should look like this Posted Image but it looks like this Posted Image

heres the code:

<?php
$con = mysql_connect("localhost","tatara","102188");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
	
if(!mysql_select_db("questbar_db", $con)) {
die('Could not connect: ' . mysql_error());
}

//used to find which user to query for in the database
$user = mysql_real_escape_string(trim($HTTP_GET_VARS['user']));

// Query
$sql = "SELECT item, have, need FROM questbar WHERE user = '$user'";

// Run Query
$result = mysql_query($sql) or die("Error retrieving user info: ".mysql_error());

// Grab the user results
while( $row = mysql_fetch_array($result) ){
   $item = $row['item'];
   $have = $row['have'];
   $need = $row['need'];
}

// You can get rid of these
//change these to get the value from the results of the query
//$item = $HTTP_GET_VARS['item'];
//$have = $HTTP_GET_VARS['have'];
//$need = $HTTP_GET_VARS['need'];

$height = 25;
$width = 200;
$fontsize = 6;
$frac = $have/$need;
$pct = 100 * $frac;

$img = imagecreate($width,$height);
$red = imagecolorallocate($img,255,0,0);
$black = imagecolorallocate($img,0,0,0);
$white = imagecolorallocate($img,255,255,255);
$bg = imageCreateFromPNG ('bg.png');
$bar =imageCreateFromPNG ('fill.png');
imageSetTile ($img, $bg);
imageFilledRectangle ($img, 0, 0, 116, 40, IMG_COLOR_TILED);
imageSetTile ($img, $bar);
ImageFilledRectangle($img, 7, 22, (114 * $frac), 34, IMG_COLOR_TILED);

$font = 'arial.ttf';
$text1 = "Questing For";
$text2 = $item;
$text3 = $have . "/" . $need;
$textwidth1 = floor(imagefontwidth($font) * strlen($text1));
$textleft1 = (($width - $textwidth1) / 2) + 12;
$textwidth2 = floor(imagefontwidth($font) * strlen($text2));
$textleft2 = (($width - $textwidth2) / 2) + 12;
imagettftext($img, $fontsize, 0, $textleft1, 8, $white, $font, $text1);
imagettftext($img, $fontsize, 0, $textleft2, 19, $white, $font, $text2);
imagettftext($img, 6, 0, 46, 32, $black, $font, $text3);

header('content-type: image/png');
imagepng($img);
    
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users