Hi;
I have an interesting problem when trying to generate an image on the fly. Here are two pieces of code:
test.php
<?php
$image = ImageCreateFromJPEG("../images/stabbs.jpg");
$cur_x = 391525;
$cur_y = 668525;
$foilist[0][0] = 392082;
$foilist[0][1] = 667385;
$foilist[1][0] = 391345;
$foilist[1][1] = 667421;
$xo = 390000;
$yo = 669454;
$xpix = 12;
$ypix = 11;
$x[0] = ceil(($cur_x - $xo)/$xpix);
$y[0] = ceil(($yo - $cur_y)/$ypix);
for ($i=0;$i<count($foilist);$i++) {
$x[] = ceil(($foilist[$i][0] - $xo)/$xpix);
$y[] = ceil(($yo - $foilist[$i][1])/$ypix);
}
Header("Content-type: image/jpeg");
$red = ImageColorAllocate($image,255,0,0);
$green = ImageColorAllocate($image,0,255,0);
for ($i=0;$i<count($x);$i++) {
if ($i == 0) ImageFilledRectangle($image,$x[$i],$y[$i],$x[$i]+5,$y[$i]+5,$red);
else ImageFilledRectangle($image,$x[$i],$y[$i],$x[$i]+5,$y[$i]+5,$green);
}
ImageJPEG($image);
ImageDestroy($image);
?>
AND showmap.php
<?php
$image = ImageCreateFromJPEG("../images/stabbs.jpg");
$cur_x = $GET["cur_x"];
$cur_y = $GET["cur_y"];
$foilist = unserialize(stripslashes($_GET["foi"]));
$xo = 390000;
$yo = 669454;
$xpix = 12;
$ypix = 11;
$x[0] = ceil(($cur_x - $xo)/$xpix);
$y[0] = ceil(($yo - $cur_y)/$ypix);
for ($i=0;$i<count($foilist);$i++) {
$x[] = ceil(($foilist[$i][1] - $xo)/$xpix);
$y[] = ceil(($yo - $foilist[$i][2])/$ypix);
}
Header("Content-type: image/jpeg");
$white = ImageColorAllocate($image,255,255,255);
$red = ImageColorAllocate($image,255,0,0);
$green = ImageColorAllocate($image,0,255,0);
for ($i=0;$i<count($x);$i++) {
if ($i == 0) ImageFilledRectangle($image,$x[$i],$y[$i],$x[$i]+5,$y[$i]+5,$red);
else ImageFilledRectangle($image,$x[$i],$y[$i],$x[$i]+5,$y[$i]+5,$green);
}
ImageJPEG($image);
ImageDestroy($image);
?>
Before the Header statement both pieces of code generate the following for the arrays $x and $y:
Array ( [0] => 128 [1] => 174 [2] => 113 ) Array ( [0] => 85 [1] => 189 [2] => 185 )
Yet, only test.php will generate a map background (stabbs.jpg) with one red box (128,85) and two green boxes (174,189) & (113,185).
showmap.php only outputs the bacground map, with no boxes at all. Yet, this is the one that I want to use. It is called from my main code using an <img> tag.
Any suggestions would be very welcome (hair loss is now at an advanced stage!!!!)
Fraser