Index: GD.php =================================================================== RCS file: /repository/pear/Image_Transform/Driver/GD.php,v retrieving revision 1.11 diff -u -r1.11 GD.php --- GD.php 23 Oct 2002 09:32:28 -0000 1.11 +++ GD.php 29 Dec 2002 06:01:46 -0000 @@ -1,4 +1,4 @@ -load('magick.png'); // // if($img->rotate($angle,array('autoresize'=>true,'color_mask'=>array(255,0,0)))){ @@ -74,8 +75,13 @@ */ function load($image) { - $this->image = $image; - $this->_get_image_details($image); + $this->image = $image; + $imageDetails = $this->_get_image_details($image); + + if (PEAR::isError($imageDetails)) { + return PEAR::raiseError($imageDetails->getMessage(), true); + } + $functionName = 'ImageCreateFrom' . $this->type; $this->imageHandle = $functionName($this->image); } // End load @@ -98,7 +104,7 @@ * @return none * @see PEAR::isError() */ - function addText($params) + function addText($params) { $default_params = array( 'text' => 'This is Text', @@ -398,6 +404,87 @@ $this->resized = false; ImageDestroy($this->old_image); $this->free(); + } + + /** + * Turn image to Grayscale + * + * The basic of grayscale is that we must turn 3 colors into 1 color. + * + * So, if you sum R+B+G and / 3 you will get just one color and you + * should use this new color in R, B and G. + * + * But, I found on the http://www.thecodeproject.com/cs/media/csharpgraphicfilters11.asp + * that if I multiple, instead of multiple by 1/3, each color by .229, .587 and .114 + * and add +3 on the color index, we will get a better image. I have not sure the why. + * + * @param float $rateR the rate of Red in the new color ($rateR/1000) + * @param float $rateG the rate of Green in the new color ($rateG/1000) + * @param float $rateB the rate of Blue in the new color ($rateB/1000) + * @param int $whiteness add more some int on the new color ($newcolor += $whiteness) + */ + function grayscale($rateR = .229, $rateG = .587, $rateB = .114, $whiteness = 3) + { + // getting number of colors on index + $numColors = imagecolorstotal($this->imageHandle); + + for ($x = 0; $x < $numColors; $x++) { + $src_colors = imagecolorsforindex($this->imageHandle,$x); + $new_color = min(255,abs($src_colors["red"] * $rateR + $src_colors["green"] * $rateG + $src_colors["blue"] * $rateB) + $whiteness); + imagecolorset($this->imageHandle,$x,$new_color,$new_color,$new_color); + } + } + + /** + * Sepia - make image pretends to be older than it really is + * + * It basicly turn the image grayscale and add some defined + * tint on it: R += 30, G += 43, B += -23, so it will appear a very old picture. + * + * @param int $tintR how much Red to add + * @param int $tintG how much Green to add + * @param int $tintB how much Blue to add + * @param float $rateR the rate of Red in the new color ($rateR/1000) + * @param float $rateG the rate of Green in the new color ($rateG/1000) + * @param float $rateB the rate of Blue in the new color ($rateB/1000) + * @param int $whiteness add more some int on the new color ($newcolor += $whiteness) + */ + function sepia($tintR = 80,$tintG = 43,$tingB = -23,$rateR = .229,$rateG = .587,$rateB = .114,$whiteness = 3) + { + // getting number of colors on index + $numColors = imagecolorstotal($this->imageHandle); + + for ($x = 0; $x < $numColors; $x++) { + $src_colors = imagecolorsforindex($this->imageHandle,$x); + $new_color = min(255,abs($src_colors["red"] * $rateR + $src_colors["green"] * $rateG + $src_colors["blue"] * $rateB) + $whiteness); + $r = min(255,$new_color + $tintR); + $g = min(255,$new_color + $tintG); + $b = min(255,$new_color + $tintB); + imagecolorset($this->imageHandle,$x,$r,$g,$b); + } + } + + /** + * Add more yellow + * + * It adds a layout of yellow that can be transparent or solid + * If $intensityA is 255 the image will be 0% transparent (solid). + * + * @param int $intensityA how much strong it will be the yellow (Red and Green) (Something between 0-255) + * @param int $intensityB how much weak will be the Blue (>= 2, in the positive limit it will be make BLUE be 0) + */ + function yelloize($intensityA = 50,$intensityB = 3) + { + // getting number of colors on index + $numColors = imagecolorstotal($this->imageHandle); + + for ($x = 0; $x < $numColors; $x++) { + $src_colors = imagecolorsforindex($this->imageHandle,$x); + $r = min($src_colors["red"] + $intensityA,255); + $g = min($src_colors["green"] + $intensityA,255); + $b = max(($r + $g) / max($intensityB,2),0); + imagecolorset($this->imageHandle,$x,$r,$g,$b); + } } /**