.PNG Image error

images php coding issues or problems here.

Moderators: macek, egami, gesf

iMod3rn
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Jan 15, 2012 8:52 am

.PNG Image error

Postby iMod3rn » Sun Jan 15, 2012 8:55 am

Hey guys, so I am trying to make a .png image with php and for some reason it says it can't make the image because there is an error somewhere.
Can someone take a look at my code and tell me what the error is?

Code: Select all

<?php
header("Content-type: image/png");
$name = addslashes($_GET['name']);
include 'mysql.php';
$q = $db->query("SELECT * FROM skills WHERE name LIKE '" . $name. "'");
$f = $db->fetch_assoc($q);
if(!$f){
   include("error_dynamic.png");
   die();
}
$sT = $f['total'];
$rank = 1;
$id = $f['id'];
$tq = @mysql_query("SELECT * FROM skills WHERE total > $sT AND mgroup != 4 AND id != $id AND banned = 0");
while($tR = @mysql_fetch_array($tq)){
   $rank++;
}
$skills = array("attack", "defence", "strength", "hitpoints", "range", "prayer", "magic", "cooking", "woodcutting", "fletching", "fishing", "firemaking", "crafting", "smithing", "mining", "thieving");
$posx = array("25", "25", "25", "25", "25", "62", "62", "62", "62", "62", "100", "100", "100", "100", "100", "135");
$posy = array("6", "24", "42", "59", "77", "6", "24", "42", "59", "77", "6", "24", "42", "59", "77", "6");
$img = imagecreatefrompng("dynamic.png");
$color = imagecolorallocate($img, 255, 255, 255);
$font = 3;
imagestring($img, $font, 158, 18, $f['name'], $color);
imagestring($img, $font, 192, 40, $f['combat'], $color);
imagestring($img, $font, 183, 51, $f['total'] ." (#$rank)", $color);
for($i = 0; $i < 16; $i++){
   $level = getLevel($f[$skills[$i]]);
   if($level < 10){
      $level = "0". getLevel($f[$skills[$i]]);
   }
   imagestring($img, $font, $posx[$i], $posy[$i], $level, $color);
}
imagepng($img);
imagedestroy($img);
function getLevel($xp){
   $lvl =1;
   while($xp > $done){
   $exp = $exp + floor($lvl + 300 * pow(2, ($lvl / 7)));

   $lvl = $lvl + 1;
   $done = floor($exp / 4);
   }
   if($lvl > 100){
   $lvl = 100;
   }
   $stuff = $lvl;
   if($xp < 83){
   $stuff = 2;
   }
   return $stuff - 1;
}

?>


Thanks

Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 0 guests

cron