<script language="php">
$debug=0;
$number="9876543210";
$number="0123456789";
$number="1111111111";
$number="2222222222";
$number="3333333333";
$number="4444444444";
$number="5555555555";
$number="6666666666";
$number="7777777777";
$number="8888888888";
$number="9999999999";
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>