All pastes #330324 Raw Edit

Someone

public text v1 · immutable
#330324 ·published 2007-01-27 20:29 UTC
rendered paste body
class ImageManipulation
{

	public $im = null;

	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);
	}
	
}