public function resize($width, $height)
{
$width = VarFilter::int($width);
$height = VarFilter::int($height);
// Generate new GD image
$newImage = imagecreatetruecolor($width, $height);
if ($this->isGif()) {
// Preserve transparency in GIFs
$transIndex = imagecolortransparent($this->_image);
$palletsize = imagecolorstotal($this->_image);
if ($transIndex >= 0 && $transIndex < $palletsize) {
$trColor = imagecolorsforindex($this->_image, $transIndex);
$red = VarFilter::int($trColor['red']);
$green = VarFilter::int($trColor['green']);
$blue = VarFilter::int($trColor['blue']);
$transIndex = imagecolorallocate($newImage, $red, $green, $blue);
imagefill($newImage, 0, 0, $transIndex);
imagecolortransparent($newImage, $transIndex);
}
} else {
// Preserve transparency in PNG
Helper::addAlpha($newImage, false);
}
// Resize
imagecopyresampled($newImage, $this->_image, 0, 0, 0, 0, $width, $height, $this->_width, $this->_height);
// Update meta data
$this->_replaceImage($newImage);
$this->_width = $width;
$this->_height = $height;
return $this;
}