protected function _do_resize($width, $height)
{
// Presize width and height
$pre_width = $this->width;
$pre_height = $this->height;
// Loads image if not yet loaded
$this->_load_image();
// Test if we can do a resize without resampling to speed up the final resize
if ($width > $this->width / 2 and $height > $this->height / 2) {
// The maximum reduction is 10% greater than the final size
$reduction_width = round($width * 1.1);
$reduction_height = round($height * 1.1);
while ($pre_width / 2 > $reduction_width and $pre_height / 2 > $reduction_height) {
// Reduce the size using an O(2n) algorithm, until it reaches the maximum reduction
$pre_width /= 2;
$pre_height /= 2;
}
// Create the temporary image to copy to
$image = $this->_create($pre_width, $pre_height);
if (imagecopyresized($image, $this->_image, 0, 0, 0, 0, $pre_width, $pre_height, $this->width, $this->height)) {
// Swap the new image for the old one
imagedestroy($this->_image);
$this->_image = $image;
}
}
// Create the temporary image to copy to
$image = $this->_create($width, $height);
// Execute the resize
if (imagecopyresampled($image, $this->_image, 0, 0, 0, 0, $width, $height, $pre_width, $pre_height)) {
// Swap the new image for the old one
imagedestroy($this->_image);
$this->_image = $image;
// Reset the width and height
$this->width = imagesx($image);
$this->height = imagesy($image);
}
}