| function Sharp2(&$im, $degree) { $cnt = 0; for ($x=imagesx($im)-1; $x>0; $x--) for ($y=imagesy($im)-1; $y>0; $y--) { $clr1 = imagecolorsforindex($im, imagecolorat($im, $x-1, $y-1)); $clr2 = imagecolorsforindex($im, imagecolorat($im, $x, $y)); $r = intval($clr2["red"]+$degree*($clr2["red"]-$clr1["red"])); $g = intval($clr2["green"]+$degree*($clr2["green"]-$clr1["green"])); $b = intval($clr2["blue"]+$degree*($clr2["blue"]-$clr1["blue"])); $r = min(255, max($r, 0)); $g = min(255, max($g, 0)); $b = min(255, max($b, 0)); //echo "r:$r, g:$g, b:$b<br>"; if (($new_clr=imagecolorexact($im, $r, $g, $b))==-1) $new_clr = Imagecolorallocate($im, $r, $g, $b); $cnt++; if ($new_clr==-1) die("color allocate faile at $x, $y ($cnt)."); imagesetpixel($im, $x, $y, $new_clr); } } |