<script language="php">
#
# this include file has the passwords and
# database names defined in it
#
# HMMMMMM somehow this include writes to the STDOUT
# which screws up the generation of the gif image
# wonder why???
#require('../sql_passwords.php');
#include('../sql_passwords.php');
$z_hardcoded_password='Amigos666';
$z_hardcoded_database='miksup_data';
$z_hardcoded_sqlurl='mysql1.100ws.com';
#
# connect to SQL
#
$link = mysql_connect($z_hardcoded_sqlurl,
$z_hardcoded_database,
$z_hardcoded_password )
or die('Could not connect: ' . mysql_error());
#
# select the database I want to use
#
mysql_select_db($z_hardcoded_database) or die('Could not select database');
$query = 'SELECT count FROM `counters` where name=\'frog\' LIMIT 0, 30 ';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$zcounter_value="";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
#echo "\t<tr>\n";
foreach ($line as $col_value) {
#echo "\t\t<td>$col_value</td>\n";
$zcounter_value=$col_value;
}
#echo "\t</tr>\n";
}
#echo "</table>\n";
mysql_free_result($result);
#echo "counter=$zcounter_value";
$number=$zcounter_value;
$nextval=$zcounter_value+1;
$query = 'update `counters` set count='.$nextval.' WHERE name=\'frog\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
// Free resultset
#mysql_free_result($result);
// Closing connection
mysql_close($link);
$debug=0;
if ($debug) {
echo "try to read in an image and display it<br>";
echo "remove these echos once i have uploaded an image to display";
echo "<p>";
echo "then read in 10 images which are the numbers 0 thru 9<p>";
echo "then get the string of ascii numbers<p>";
echo "then walk thru the string of numbers and caculate the width of the image<br>";
echo "and use the highest height<p>";
echo "next generate the image<p>";
echo "next copy the numbers to the image<p>";
}
# set these to the image width and height
# after we caculate it from the digits in the image
$xxheight=1;
$xxwidth=0;
#
# read in the 10 digit images
# may have to change this from PNG to GIF to JPG
#
$ifiles[0]='0.gif';
$ifiles[1]='1.gif';
$ifiles[2]='2.gif';
$ifiles[3]='3.gif';
$ifiles[4]='4.gif';
$ifiles[5]='5.gif';
$ifiles[6]='6.gif';
$ifiles[7]='7.gif';
$ifiles[8]='8.gif';
$ifiles[9]='9.gif';
#
# loop thru and open a gif file for each number from 0 to 9
#
for ($i=0;$i<10;$i++) {
#list($zwidth, $zheight, $ztype, $zattr)=getimagesize($ifiles[$i]);
$size=getimagesize($ifiles[$i]);
$gif_width[$i]=$size[0];
$gif_height[$i]=$size[1];
if ($gif_height[$i] > $xxheight ) {
$xxheight=$gif_height[$i];
}
if ($debug) {
echo "file=$ifiles[$i] <br>";
echo "size= $size <br>";
echo "size[0]= $size[0] <br>";
echo "size[1]= $size[1] <br>";
echo "size[2]= $size[2] <br>";
echo "size[3]= $size[3] <br>";
echo "size[4]= $size[4] <br>";
echo "width[$i]=$gif_width[$i]<br>";
echo "height[$i}=$gif_height[$i]<br>";
echo "max height=$xxheight<br>";
}
$gif[$i]=@imagecreatefromgif ($ifiles[$i]);
if (!$gif[$i]) {
echo "error reading file $ifiles[$i] for image $i<br>";
}
}
#
# get the total width of the image
# by adding up the width of each digit in the number
#
for ($i=0;$i<strlen($number);$i++) {
if ($debug) {
echo "old[$i]=$xxwidth<br>";
}
$thisdigit=substr($number,$i,1);
if ($debug) {
echo "current=$gif_width[$thisdigit]<br>";
}
$xxwidth+=$gif_width[$thisdigit];
if ($debug) {
echo "new[$i]=$xxwidth<br>";
}
}
#
# create the image
#
$image=ImageCreate($xxwidth, $xxheight);
#
# set the R,G,B background color of the imagee
#
$background_color=ImageColorAllocate($image,255,0,0);
#
# define RGB black as a color used on the image
#
$black=ImageColorAllocate($image,0,0,0);
#
# copy the color $black into the image between 0,0 and 50,50
#
#ImageFilledRectangle($image,0,0,$xxwidth,$xxheight,$black);
#
# convert the $number to an image
# copy each digit of the number to our image from left to right
#
if ($debug) {
echo "convert this number ($number) to an image<br>";
}
$next_x=0;
for ($i=0;$i<strlen($number);$i++) {
$thisdigit=substr($number,$i,1);
$zfile=$ifiles[$thisdigit];
$zhandle=$gif[$thisdigit];
if ($debug) {
echo "digit($i)=$thisdigit ";
echo "use file $ifiles[$thisdigit] ";
echo "handle($zhandle) ";
echo "to x $next_x ";
echo "<br>";
}
#
# copy the gif image to our image
#
$rc=imagecopy ( $image, $zhandle,
$next_x, ($xxheight - $gif_height[$thisdigit]) ,
0, 0,
$gif_width[$thisdigit],$xxheight);
$rc=$rc?"true":"failed";
if ($debug) {
echo "imagecopy rc=$rc<br>";
}
$next_x=$next_x+ $gif_width[$thisdigit];
}
#
# return the image
#
header("Content-Type: image/png");
ImagePNG($image);
</script>