/** * Re-sizes the image. If $height is not specified, it will default to $width, creating a square. * * @param int $targetWidth * @param int|null $targetHeight * * @return Image */ public function resize($targetWidth, $targetHeight = null) { $this->normalizeDimensions($targetWidth, $targetHeight); if ($this->_isAnimatedGif) { $this->_image->layers()->coalesce(); // Create a new image instance to avoid object references messing up our dimensions. $newSize = new \Imagine\Image\Box($targetWidth, $targetHeight); $gif = $this->_instance->create($newSize); $gif->layers()->remove(0); foreach ($this->_image->layers() as $layer) { $resizedLayer = $layer->resize($newSize, $this->_getResizeFilter()); $gif->layers()->add($resizedLayer); // Let's update dateUpdated in case this is going to take awhile. if ($index = craft()->assetTransforms->getActiveTransformIndexModel()) { craft()->assetTransforms->storeTransformIndexData($index); } } $this->_image = $gif; } else { if (craft()->images->isImagick()) { $this->_image->smartResize(new \Imagine\Image\Box($targetWidth, $targetHeight), (bool) craft()->config->get('preserveImageColorProfiles'), $this->_quality); } else { $this->_image->resize(new \Imagine\Image\Box($targetWidth, $targetHeight), $this->_getResizeFilter()); } } return $this; }
/** * Re-sizes the image. If $height is not specified, it will default to $width, creating a square. * * @param int $targetWidth * @param int|null $targetHeight * * @return Image */ public function resize($targetWidth, $targetHeight = null) { $this->normalizeDimensions($targetWidth, $targetHeight); if ($this->_isAnimatedGif) { // Create a new image instance to avoid object references messing up our dimensions. $newSize = new \Imagine\Image\Box($targetWidth, $targetHeight); $gif = $this->_instance->create($newSize); $gif->layers()->remove(0); foreach ($this->_image->layers() as $layer) { $resizedLayer = $layer->resize($newSize, $this->_getResizeFilter()); $gif->layers()->add($resizedLayer); } $this->_image = $gif; } else { if (craft()->images->isImagick()) { $this->_image->smartResize(new \Imagine\Image\Box($targetWidth, $targetHeight), (bool) craft()->config->get('preserveImageColorProfiles'), $this->_quality); } else { $this->_image->resize(new \Imagine\Image\Box($targetWidth, $targetHeight), $this->_getResizeFilter()); } } return $this; }