Codice PHP:
<?
if(isset($_GET['r']) && is_numeric($_GET['r'])){$r=$_GET['r'];}else{$r=10;}
if(isset($_GET['d']) && is_numeric($_GET['d'])){$d=$_GET['d'];}else{$d=10;}
$file="image.png";
$im=imagecreatefrompng($file);
$xsize=imagesx($im);
$ysize=imagesy($im);
$im2=imagecreate($xsize,$ysize);
$c_black=imagecolorallocate($im2,0,0,0);
$c_white=imagecolorallocate($im2,255,255,255);
imagefill($im2,0,0,$c_white);
for($y=1;$y<$ysize;$y++){
for($x=1;$x<$xsize;$x++){
$c=imagecolorat($im,$x,$y);
$color=imagecolorsforindex($im, $c);
if(($y+1)<$ysize){
$c=imagecolorat($im,$x,$y+1);
$colorya=imagecolorsforindex($im, $c);
}
$doit=false;
if(!isset($prec)){
$prec=$color;
}
if($prec['red'] < ($color['red']-$r) || $prec['red'] > ($color['red']+$r)){
imagesetpixel($im2,$x,$y,$c_black);
$doit=true;
}
if($prec['green'] < ($color['green']-$r) || $prec['green'] > ($color['green']+$r)){
imagesetpixel($im2,$x,$y,$c_black);
$doit=true;
}
if($prec['blue'] < ($color['blue']-$r) || $prec['blue'] > ($color['blue']+$r)){
imagesetpixel($im2,$x,$y,$c_black);
$doit=true;
}
if($color['red'] < ($colorya['red']-$r) || $color['red'] > ($colorya['red']+$r)){
imagesetpixel($im2,$x,$y,$c_black);
}
if($color['green'] < ($colorya['green']-$r) || $color['green'] > ($colorya['green']+$r)){
imagesetpixel($im2,$x,$y,$c_black);
}
if($color['blue'] < ($colorya['blue']-$r) || $color['blue'] > ($colorya['blue']+$r)){
imagesetpixel($im2,$x,$y,$c_black);
}
if($doit==true){
$x++;
}else{
// non è un bordo, renderizzo come colore: QUI NON FUNZIONA!!!!!
$colore=imagecolorallocate($im2,$color['red'],$color['green'],$color['blue']);
imagesetpixel($im2,$x,$y,$colore);
}
$prec=$color;
}
}
header('Content-type: image/png');
imagepng($im2);
?>