Create a PNG
Posted: Sun Mar 25, 2007 3:18 am
Well I have a script and it is pretty self explanatory. A form posts values to it, it uses GD to create an image, and uses some file functions to create a file called $pid.php.
I can use the <img src=".....$pid.php" /> to display the *image* but what I want it to do is actually create a png file rather than a php file.
I know the imagepng() function allows you to specify the name of the image, but the way I have it currently setup, when i submit the first form it creates the file $pid.php and I have to execute that (http://www....../$pid.php) file for the png file to be created. So my question is, how can I make the png file automatically created once the form is submitted?
I can use the <img src=".....$pid.php" /> to display the *image* but what I want it to do is actually create a png file rather than a php file.
I know the imagepng() function allows you to specify the name of the image, but the way I have it currently setup, when i submit the first form it creates the file $pid.php and I have to execute that (http://www....../$pid.php) file for the png file to be created. So my question is, how can I make the png file automatically created once the form is submitted?
Code: Select all
<?php
$stat1 = $_POST['stat1'];
$stat2 = $_POST['stat2'];
$stat3 = $_POST['stat3'];
$stat4 = $_POST['stat4'];
$stat5 = $_POST['stat5'];
$stat6 = $_POST['stat6'];
$stat7 = $_POST['stat7'];
$stat8 = $_POST['stat8'];
$stat9 = $_POST['stat9'];
$pid = $_POST['pid'];
$sig = "<?php
header('Content-type: image/png');
/**** Variables ****/
\$r = 0;
\$g = 0;
\$b = 0;
\$bgImage = \"bg-sidewinder.png\";
/*******************/
\$im = imagecreatefrompng (\$bgImage);
\$color = imagecolorallocate(\$im, \$r, \$g, \$b);
include(\"../config.php\");
\$result = mysql_query(\"SELECT * FROM \". \$dbtable .\" WHERE pid = '$pid'\", \$db);
while (\$row = mysql_fetch_assoc(\$result)) {
\$text[1] = \$row['$stat1'];
\$text[2] = \$row['$stat2'];
\$text[3] = \$row['$stat3'];
\$text[4] = \$row['$stat4'];
\$text[5] = \$row['$stat5'];
\$text[6] = \$row['$stat6'];
\$text[7] = \$row['$stat7'];
\$text[8] = \$row['$stat8'];
\$text[9] = \$row['$stat9'];
}
\$font = 'arial.ttf';
\$size[1] = 7;
\$size[2] = 9;
imagettftext(\$im, \$size[2], 0, 15, 21, \$color, \$font, \$text[1]);
imagettftext(\$im, \$size[2], 0, 190, 21, \$color, \$font, \$text[2]);
imagettftext(\$im, \$size[1], 0, 65, 45, \$color, \$font, \$text[3]);
imagettftext(\$im, \$size[1], 0, 250, 45, \$color, \$font, \$text[4]);
imagettftext(\$im, \$size[1], 0, 50, 64, \$color, \$font, \$text[5]);
imagettftext(\$im, \$size[1], 0, 260, 64, \$color, \$font, \$text[6]);
imagettftext(\$im, \$size[1], 0, 63, 82, \$color, \$font, \$text[7]);
imagettftext(\$im, \$size[1], 0, 259, 82, \$color, \$font, \$text[8]);
imagettftext(\$im, \$size[1], 0, 78, 100, \$color, \$font, \$text[9]);
imagepng(\$im, $pid.png);
imagedestroy(\$im);
?>";
$fp = fopen("$pid.php", "w");
fputs($fp, $sig);
fclose($fp);
echo "The image has been created...";
?>