Forum

ASSIST, AMERICA'S ARMY COMMUNITY - RELIVE THE GLORY DAYS OF AMERICA'S ARMY 2.5

Author Topic: Spanky, I need help!  (Read 1158 times)

0 Members and 1 Guest are viewing this topic.

-Delta-

  • Guest
Spanky, I need help!
« on: Monday, November 29, 2010, 13:43:01 PM »
My PHP code isn't working and I don't know why.  :'(

Code: [Select]
<?php

function StatsToImage($username
{
$font './fonts/times.ttf'// Font to use to generate the image.

$fontSize 8// font size.
$transparent true;
$fg_color = array(000);
$bg_color = array(255255255);

$msg "";
$Points "";
$Rank "";

$lines file('http://www.worldcommunitygrid.org/getDynamicImage.do?memberName='$username'&mnOn=true&stat=1&imageNum=1&rankOn=true&projectsOn=false&special=false');
foreach ($lines as $line_num => $line) {
$pos strripos(htmlspecialchars($line), ";Points");
if ($pos) {
$Points $line;
$pos strripos($Points "&");
$Points substr($Points0$pos);
$Points trim($Points" \t.");
}

$pos strripos(htmlspecialchars($line), "(Rank");
if ($pos) {
$Rank $line;
$pos strripos($Rank ";");
$Rank substr($Rank$pos+1strlen($Rank));
$pos strripos($Rank ")");
$Rank substr($Rank0$pos);
$Rank trim($Rank" \t.");
}
}

$msg "Username: "$username"  |  Points: "$Points"  |  Rank: "$Rank;

$width 0;
$height 0;
$image null;
// Determine font height
$bounds imagettfbbox(80$font"W");
echo $msg;
$font_height abs($bounds[7]-$bounds[1]);

// Determine image size.
$bounds ImageTTFBBox($fontSize0$font$msg);
$width abs($bounds[4]-$bounds[6]);
$height abs($bounds[7]-$bounds[1]);

$image imagecreate($width+1$height+1); // Initialize type image
$background ImageColorAllocate($image$bg_color[0], $bg_color[1], $bg_color[2]);
$foreground ImageColorAllocate($image$fg_color[0], $fg_color[1], $fg_color[2]);

if ($transparent) {
ImageColorTransparent($image$background);
}

// Build image from text.
ImageTTFText($image$fontSize00$font_height$foreground$font$msg);

// Save PNG to file.
imagepng($image"stats.png");
}

StatsToImage("computerguy89"); // Call function
?>


It seems to crash right around when "imagettfbbox" is called, but php won't give me any debug information. This is also the same code I was using before, and nothing has changed. So, it doesn't really make sense that it is not working.

Offline Spanky

  • <?php echo $opinion .' is better.'; ?>
  • Administrator
  • Posts like a Spanky!
  • *
  • Posts: 10,893
    • View Profile
    • NatesComp.com
  • AA: tigobitties
Re: Spanky, I need help!
« Reply #1 on: Monday, November 29, 2010, 14:36:59 PM »
Well....
http://natescomp.com/delta.php

It looks to work but not use font. I changed the font to the one used for PostQuote sigs. Maybe I have the directory structure wrong, I don't know. What I do know is that for things like imagettfbbox and imagecolorallocate, don't capitalize anything. I also don't think you need the call function and a simple rewrite can fix that. I can look more into it later if you want.

*EDIT*
I also don't like $image = null; it just doesn't seem right.
« Last Edit: Monday, November 29, 2010, 14:51:26 PM by Spanky »
It's like shaving your pubes to make your junk look bigger.
Might look bigger, but it aint.....

Jared

  • Guest
Re: Spanky, I need help!
« Reply #2 on: Monday, November 29, 2010, 18:56:08 PM »
Your not calling the headers in order to have an image.


-Delta-

  • Guest
Re: Spanky, I need help!
« Reply #3 on: Monday, November 29, 2010, 21:25:03 PM »
Thanks for your help guys. When I get time to work on it I'll try what you said.

Offline Spanky

  • <?php echo $opinion .' is better.'; ?>
  • Administrator
  • Posts like a Spanky!
  • *
  • Posts: 10,893
    • View Profile
    • NatesComp.com
  • AA: tigobitties
Re: Spanky, I need help!
« Reply #4 on: Monday, November 29, 2010, 21:54:29 PM »
Delta, if you want, you can scavenge the code for PostQuote. Both me and Jared have contributed to it so keep that in mind if you share it with other people :)

Code: [Select]
<?php
$db 
mysql_connect("localhost""xxxxxxxxxxx""xxxxxxxxxxx") or die ('There was a problem connecting to the database.');
mysql_select_db("natcom_quotes") or die ('There was a problem selecting database table.');
header("Content-type: image/png");

// Update Signatures Served
$sql "SELECT * FROM signatures";
$rs_result mysql_query ($sql);
while ($row mysql_fetch_assoc($rs_result)) {
    
$sigtotal $row['total'];};
$sigtotaladd $sigtotal+1;
mysql_query("UPDATE signatures SET total='".$sigtotaladd."' WHERE total='".$sigtotal."'");

$urluser $_GET['u'];
$sql_events mysql_query("SELECT * FROM quotes ORDER BY servtime DESC limit 1")
or die(
mysql_error());
while (
$row mysql_fetch_array($sql_events))
{
    
$username $row['username'];
    
$quote1 htmlspecialchars_decode($row['quote']);
    
$quote2 mb_substr($quote10500,'UTF-8');
    
//
    
$order   = array("\r\n""\n""\r");
$replace "\n";
// Processes \r\n's first so they aren't converted twice.
$quote str_replace($order$replace$quote2);
    
$servtime $row['servtime'];
   
$by htmlspecialchars_decode($row['by']);
   
$id $row['id'];
   
$ratingup $row['voteup'];
$ratingdown $row['votedown'];
}
mysql_close($db);
$image imagecreatefrompng("sigbackground.png");
imagealphablending($imagetrue);
imagesavealpha($imagetrue);

$font "./verdana.ttf";

//imagecolorallocate($image, R, G, B) in HEX values
$font_black imagecolorallocate($image218);

//($image, fontsize, rightindent, downindent, data, txtcolour)
imagettftext($image80510$font_black$font"Newest quote posted on PostQuote.us:");
imagettftext($image8035210$font_black$font"ID: $id");

/////
$srt wordwrap($quote68"\n");
$lines explode("\n"$srt);
$y 24;
$i 0;
foreach(
$lines as $line=>$string){
imagettftext($image805$y$font_black$font$string);
$string substr($string1);
$y += 12;
if(++$i == 6) break;
}
/////

// Display the rest of the info
imagettftext($image80597$font_black$font"-$by");
imagettftext($image80200112$font_black$font$ratingup);
imagettftext($image80240112$font_black$font$ratingdown);

imagepng($image);
imagedestroy($image);
?>

You save that as index.php in a directory called "sig.png". This way whenever a browser asks for http://myhost.com/sig.png they actually get http://myhost.com/sig.png/index.php useful for forums and whatnot :)
It's like shaving your pubes to make your junk look bigger.
Might look bigger, but it aint.....

 

Download Assist

×

Download Game Client

Important: Battletracker no longer exists. However, old Battletracker accounts may still work. You can create a new 25Assist account here

Download Server Manager