Page 1 of 1

save a php generated image as an image file

Posted: Sun Aug 06, 2006 8:41 pm
by SidewinderX
ive created this image using imagecreatefrompng() ( http://www.extreme-hq.com/stats/bhdstat ... 994163.php )
it displays my stats from a game (dynamically, it updates every hour)
however for the image to show i need to use

Code: Select all

<img src="http://www.extreme-hq.com/stats/bhdstatsigs/13622994163.php"></img>
Unfortunally a lot of forums disallow the img tags for signatures and only allow the phpBB code, and as a result my signature wont show.
Fortunally i have these forums to help me fix this problem :)

Is there any way, once the page updates to save the image as an actual image file (gif, jpg, or png) rather than a php file? I also recall seeing somewhere a .htaccess file would do the trick? but i dont recall. So what are your thoughts?

Thank You.

Posted: Sun Aug 06, 2006 8:43 pm
by feyd
imagepng() or whatever you use has an option for giving it a filename.

Posted: Sun Aug 06, 2006 8:55 pm
by SidewinderX
thats a handy little option :)

from what i gather i would just do this

Code: Select all

imagepng($im, 'ozymandias.png');
but that gives me an error :?:

Code: Select all

<?php

$db = mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db($dbname, $db);

mysql_select_db("extreme_statsig",$db);
$result = mysql_query("SELECT * FROM bhdsigs WHERE pid = '33680801261'", $db);

while ($row = mysql_fetch_assoc($result))
{
extract($row);

// Set the content-type
header('Content-type: image/png');

// Create the image
$im = imagecreatefrompng ("background1.png");

// Create some colors
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);

// The text to draw
$text[0] = "$player_name";
$text[1] = "EXP POINTS: $team_experience_points";
$text[2] = "KILLS: $total_kills";
$text[3] = "HS RATIO: $head_shot_ratio";
$text[4] = "FB LEVELS: $flag_levels";
$text[5] = "MINS PLAYED: $minutes_played";
$text[6] = "DEATHS: $deaths";
$text[7] = "BW LEVELS: 19";
$text[8] = "HEAD SHOTS: $total_head_shots";
$text[9] = "$player_rank";
$text[10] = "YELLOWS: $killed_2_for_1";
$text[11] = "RATIO: $kill_death_ratio";
$text[12] = "DM LEVELS: $dm_levels";
$text[13] = "KOTH LEVELS: $koth_levels";

// Font to use
$font = '04B_09__.TTF';
// The text size
$size[0] = 13;
$size[1] = 6;
// Add the text
imagettftext($im, $size[1], 0, 5, 27, $red, $font, $text[0]);
imagettftext($im, $size[1], 0, 5, 50, $red, $font, $text[1]);
imagettftext($im, $size[1], 0, 5, 68, $red, $font, $text[2]);
imagettftext($im, $size[1], 0, 5, 85, $red, $font, $text[3]);
imagettftext($im, $size[1], 0, 5, 103, $red, $font, $text[4]);
imagettftext($im, $size[1], 0, 122, 50, $red, $font, $text[5]);
imagettftext($im, $size[1], 0, 122, 68, $red, $font, $text[6]);
imagettftext($im, $size[1], 0, 122, 103, $red, $font, $text[7]);
imagettftext($im, $size[1], 0, 122, 85, $red, $font, $text[8]);
imagettftext($im, $size[1], 0, 237, 27, $red, $font, $text[9]);
imagettftext($im, $size[1], 0, 237, 50, $red, $font, $text[10]);
imagettftext($im, $size[1], 0, 237, 68, $red, $font, $text[11]);
imagettftext($im, $size[1], 0, 237, 85, $red, $font, $text[12]);
imagettftext($im, $size[1], 0, 237, 103, $red, $font, $text[13]);

imagepng($im, 'ozymandias.png');
imagedestroy($im);
}
?>
FIXED: didnt chmod the directory