All pastes #330326 Raw Edit

Stuff

public text v1 · immutable
#330326 ·published 2007-01-27 20:35 UTC
rendered paste body
<?php

$im = imagecreatefromjpeg('test.jpg');
//$im = ImageSelectiveColor($im,0,127,127);
$im = redeye($im);
imagejpeg($im,'out.jpg');
new image('c:\php-gtk\test.jpg');
function redeye($im){
	$width=imageSX($im);
   	$height=imageSY($im);
   	for ($x = 0; $x < $width; $x++)
   	{
   		for ($y = 0; $y < $width; $y++)
   		{
   			$index = imagecolorat($im, $x, $y);
   			$color = imagecolorsforindex($im, $index);
   			$green = round(($color['green'] / 100) * 50);
   			$blue = round(($color['blue'] / 100) * 50);
   			$newcolor = imagecolorallocate($im, 0, $green, $blue);
   			imagesetpixel($im,$x,$y,$newcolor);
   		}
   	}
	return $im;
}

class ImageManipulation
{

	protected $im = null;
	protected $width = 0;
	protected $height = 0;

	public function __construct($file)
	{
		// put gd in $this->im
	}
	
	public function get_rgb_channels()
	{
		$width=imageSX($im);
   		$height=imageSY($im);
   		$red_channel = imagecreate($width, $height);
   		imagecopy($red_channel,$im,0,0,0,0,$width,$height);
   		$green_channel = imagecreate($width, $height);
   		imagecopy($green_channel,$im,0,0,0,0,$width,$height);
   		$blue_channel = imagecreate($width, $height);
   		imagecopy($blue_channel,$im,0,0,0,0,$width,$height);
   		for ($x = 0; $x < $width; $x++)
   		{
   			for ($y = 0; $y < $width; $y++)
   			{
   				$index = imagecolorat($this->im, $x, $y);
   				$color = imagecolorsforindex($this->im, $index);
   				$red = $color['red'];
   				$green = $color['green'];
   				$blue = $color['blue'];
   				$red_index = imagecolorat($red_channel, $x, $y);
   				$green_index = imagecolorat($green_channel, $x, $y);
   				$blue_index = imagecolorat($blue_channel, $x, $y);
   				$red_color = imagecolorallocate($red_channel, $red, 0, 0);
   				$green_color = imagecolorallocate($green_channel, 0, $green, 0);
   				$blue_color = imagecolorallocate($blue_channel, 0, 0, $blue);
   				imagesetpixel($red_channel,$x,$y,$red_color);
   				imagesetpixel($green_channel,$x,$y,$green_color);
   				imagesetpixel($blue_channel,$x,$y,$blue_color);
   			}
   		}
   		return array('red'=>$red_channel,'green'=>$green_channel,'blue'=>$blue_channel);
	}
	
	public function resize($width,$height)
	{
		$im = imagecreate($width, $height);
		imagecopyresized($im, $this->im, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
		$this->im = $im;
		$this->width = $width;
		$this->height=$height;
		return $this->im;
	}
	
}

?>