note 77841 deleted from function.imagecolorat by nlopess

From: Date: Sat, 15 Sep 2007 19:09:23 +0000
Subject: note 77841 deleted from function.imagecolorat by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130523@lists.php.net to get a copy of this message
Note Submitter: pocze_zsolt at hotmail dot com ---- This is a histogram-stretchng function to get a better contrast. function contrast_stretch( $img ) { $x = imagesx($img); $y = imagesy($img); $min=255.0; $max=0.0; for($i=0; $i<$y; $i++) { for($j=0; $j<$x; $j++) { $pos = imagecolorat($img, $j, $i); $f = imagecolorsforindex($img, $pos); $gst = $f["red"]*0.15 + $f["green"]*0.5 + $f["blue"]*0.35; if($gst>$max) $max=$gst; if($gst<$min) $min=$gst; } } $distance = $max-$min; for($i=0; $i<$y; $i++) { for($j=0; $j<$x; $j++) { $pos = imagecolorat($img, $j, $i); $f = imagecolorsforindex($img, $pos); $red = 255*($f["red"]-$min)/$distance; $green = 255*($f["green"]-$min)/$distance; $blue = 255*($f["blue"]-$min)/$distance; if($red<0) $red = 0.0; elseif($red>255) $red=255.0; if($green<0) $green = 0.0; elseif($green>255) $green=255.0; if($blue<0) $blue = 0.0; elseif($blue>255) $blue=255.0; $color = imagecolorresolve($img, $red, $green, $blue); imagesetpixel($img, $j, $i, $color); } } }

« previous php.notes (#130523) next »