Vampireofdarkness
asked on
Image creation via PHP
Hi, I have recently been working on a script which will create an image via PHP, but seems to have stumbled upon a big error.
My script is..
<?
if($ploc=="Hev") { $im = imagecreatefrompng('Hev.pn g'); }
else if($ploc=="Sky") { $im = imagecreatefrompng('Sky.pn g'); }
else if($ploc=="Sur") { $im = imagecreatefrompng('Sur.pn g'); }
else if($ploc=="Dun") { $im = imagecreatefrompng('Dun.pn g'); }
else if($ploc=="Hel") { $im = imagecreatefrompng('Hel.pn g'); }
$kdc=0;
$kds=0;
?>
<script language="JavaScript" type="text/javascript">
function loc(x,y) { s_Loc.innerHTML="Location: "+x+","+y; }
function ut() { s_Loc.innerHTML="<br>"; }
function kd(kdnum) { s_KD.innerHTML=kdnum; }
function kds(kdnum) { s_KDS.innerHTML=kdnum; }
</script>
<?
echo "Number of kingdoms: <span id=s_KD>".$kdc."</span> || Kingdoms Checked: <span id=s_KDS>".$kds."</span><p ><span id=s_Pic>Old :: <br><img src=result.jpeg></span><p> ";
$width=300;
$height=300;
$image=imagecreate($width, $height);
$bg=imagecolorallocate($im age, 0x00,0x00,0x00);
for ($i=0;$i<300;$i++){
for ($j=0;$j<300;$j++){
$start_x = $j;
$start_y = $i;
$color=imagecolorat($im, $start_x, $start_y);
if($color==$colour) {
$kdc++;
imagesetpixel($image,$star t_x,$start _y,$color) ;
}
$kds++;
}
echo "<script>kds(\"".number_fo rmat($kds) ."\");</sc ript>";
echo "<script>kd(\"".number_for mat($kdc). "\");</scr ipt>";
}
imagejpeg($image,"result.j peg");
imagedestroy($image);
echo "<p>New :: <br><img src=result.jpeg>";
?>
The imagesetpixel() seems to not be working at all and therefore it prints a fully black image. This shouldn't happen. Can anyone suggest a fix? (based on the above script). Quickest and most efficient answer gets..... ooooohh.... 75 points?
EDIT: Upped to 100
My script is..
<?
if($ploc=="Hev") { $im = imagecreatefrompng('Hev.pn
else if($ploc=="Sky") { $im = imagecreatefrompng('Sky.pn
else if($ploc=="Sur") { $im = imagecreatefrompng('Sur.pn
else if($ploc=="Dun") { $im = imagecreatefrompng('Dun.pn
else if($ploc=="Hel") { $im = imagecreatefrompng('Hel.pn
$kdc=0;
$kds=0;
?>
<script language="JavaScript" type="text/javascript">
function loc(x,y) { s_Loc.innerHTML="Location:
function ut() { s_Loc.innerHTML="<br>"; }
function kd(kdnum) { s_KD.innerHTML=kdnum; }
function kds(kdnum) { s_KDS.innerHTML=kdnum; }
</script>
<?
echo "Number of kingdoms: <span id=s_KD>".$kdc."</span> || Kingdoms Checked: <span id=s_KDS>".$kds."</span><p
$width=300;
$height=300;
$image=imagecreate($width,
$bg=imagecolorallocate($im
for ($i=0;$i<300;$i++){
for ($j=0;$j<300;$j++){
$start_x = $j;
$start_y = $i;
$color=imagecolorat($im, $start_x, $start_y);
if($color==$colour) {
$kdc++;
imagesetpixel($image,$star
}
$kds++;
}
echo "<script>kds(\"".number_fo
echo "<script>kd(\"".number_for
}
imagejpeg($image,"result.j
imagedestroy($image);
echo "<p>New :: <br><img src=result.jpeg>";
?>
The imagesetpixel() seems to not be working at all and therefore it prints a fully black image. This shouldn't happen. Can anyone suggest a fix? (based on the above script). Quickest and most efficient answer gets..... ooooohh.... 75 points?
EDIT: Upped to 100
ASKER
Oh, sorry.
$colour is a variable from a previous page (appears in /xx.php?colour=xx)
$ploc is also the same
$colour is a variable from a previous page (appears in /xx.php?colour=xx)
$ploc is also the same
ASKER
and imagesetpixel does get called as it shows that there are 10,144 color matches
ASKER
Found a solution for myself... now to close this....
Thanks for your help anyway
Thanks for your help anyway
I believe posting on the CS area will get it removed for you.
Was it a bad setting of $colour or something else?
Was it a bad setting of $colour or something else?
ASKER
All I needed to do was define $colour before the loop with
$black=imagecolorallocate( $image, 0x00,0x00,0x00);
for a black colour, etc..etc.. then use those colours.
$black=imagecolorallocate(
for a black colour, etc..etc.. then use those colours.
Ah, so $colour was simply being defined in the loop and constantly matching up with the value of black?
ASKER
$colour wasn't being defined, for some reason although it should have been. Which is why it posted black.
That's what I had suspected when I saw it wasn't defined. It was being defined with a default nothing value and so then black always matched with it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you verified the color value and the fact that imagesetpixel even gets called?