// case-study: php pixel editor with imagemap
// 07.10.2003 by andre schmidt
$size_x = 8; //image width
$size_y = $size_x; //image height (doesnt work yet!)
$zoom_f = 20; //zoomfactor
//create new image
if ($_GET['area']==''){
$img = imagecreatetruecolor($size_x*$zoom_f+1,$size_y*$zoom_f+1);
$white = imagecolorallocate($img,255,255,255);
$lgray = imagecolorallocate($img,196,196,196);
imagefill($img,0,0,$white);
for ($y=0; $y<$size_y; $y++){
$yy = $y*$zoom_f;
for ($x=0; $x<$size_x; $x++){
$xx = $x*$zoom_f;
imagerectangle($img,$xx,$yy,$xx+$zoom_f,$yy+$zoom_f,$lgray);
}
}
imagepng($img,"icon.png");
imagedestroy($img);
}
//edit image
else {
$img = imagecreatefrompng("icon.png");
$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
$lgray = imagecolorallocate($img,196,196,196);
$a = $_GET['area'];
$y0 = floor($a/$size_x)*$zoom_f;
$y1 = $y0 + $zoom_f;
$x0 = fmod($a,$size_x)*$zoom_f;
$x1 = $x0 + $zoom_f;
$c = imagecolorat($img,$x0+3,$y0+3);
if ($c == 0){
imagefilledrectangle($img,$x0,$y0,$x1,$y1,$white);
imagerectangle($img,$x0,$y0,$x1,$y1,$lgray);
}
else{
imagefilledrectangle($img,$x0,$y0,$x1,$y1,$black);
imagerectangle($img,$x0,$y0,$x1,$y1,$lgray);
}
imagepng($img,"icon.png");
imagedestroy($img);
}
//create imagemap
echo "";
?>