rendered paste bodyclass ImageManipulation
{
protected $im = null;
protected $width = 0;
protected $height = 0;
public function __construct($file)
{
// put gd in $this->im
}
public function get_gd()
{
return $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;
}
public function crop($left, $right, $top, $bottom)
{
$width = $this->width - $left - $right;
$height = $this->height - $top - $bottom;
$temp = imagecreate($width,$height);
imagecopy( $temp, $this->im, $right, $bottom, $left, $top, $width, $height );
$this->im = $temp;
$this->width=$width;
$this->height=$height;
return $temp;
}
}