public function thumbnail(array $options = []) {
		if (empty($options['height']) || empty($options['width'])) {
			throw new \InvalidArgumentException(__d('imagine', 'You have to pass height and width in the options!'));
		}

		$mode = ImageInterface::THUMBNAIL_INSET;
		if (isset($options['mode']) && $options['mode'] === 'outbound') {
			$mode = ImageInterface::THUMBNAIL_OUTBOUND;
		}

		$filter = ImageInterface::FILTER_UNDEFINED;
		if (isset($options['filter'])) {
			$filter = $options['filter'];
		}

		$size = new Box($options['width'], $options['height']);
		$imageSize = $this->_image->getSize();
		$ratios = array(
			$size->getWidth() / $imageSize->getWidth(),
			$size->getHeight() / $imageSize->getHeight()
		);

		// if target width is larger than image width
		// AND target height is longer than image height
		if ($size->contains($imageSize)) {
			return $this->_image;
		}
		if ($mode === ImageInterface::THUMBNAIL_INSET) {
			$ratio = min($ratios);
		} else {
			$ratio = max($ratios);
		}
		if ($mode === ImageInterface::THUMBNAIL_OUTBOUND) {
			if (!$imageSize->contains($size)) {
				$size = new Box(
					min($imageSize->getWidth(), $size->getWidth()),
					min($imageSize->getHeight(), $size->getHeight())
				);
			} else {
				$imageSize = $this->_image->getSize()->scale($ratio);
				$this->_image->resize($imageSize, $filter);
			}
			$this->_image->crop(new Point(
				max(0, round(($imageSize->getWidth() - $size->getWidth()) / 2)),
				max(0, round(($imageSize->getHeight() - $size->getHeight()) / 2))
			), $size);
		} else {
			if (!$imageSize->contains($size)) {
				$imageSize = $imageSize->scale($ratio);
				$this->_image->resize($imageSize, $filter);
			} else {
				$imageSize = $this->_image->getSize()->scale($ratio);
				$this->_image->resize($imageSize, $filter);
			}
		}

		return $this;
	}
public function thumbnail(array $options = []) {
		if (empty($options['height']) || empty($options['width'])) {
			throw new \InvalidArgumentException(__d('imagine', 'You have to pass height and width in the options!'));
		}

		$mode = ImageInterface::THUMBNAIL_INSET;
		if (isset($options['mode']) && $options['mode'] === 'outbound') {
			$mode = ImageInterface::THUMBNAIL_OUTBOUND;
		}

		$filter = ImageInterface::FILTER_UNDEFINED;
		if (isset($options['filter'])) {
			$filter = $options['filter'];
		}

		$size = new Box($options['width'], $options['height']);
		$imageSize = $this->_image->getSize();
		$ratios = array(
			$size->getWidth() / $imageSize->getWidth(),
			$size->getHeight() / $imageSize->getHeight()
		);

		// if target width is larger than image width
		// AND target height is longer than image height
		if ($size->contains($imageSize)) {
			return $this->_image;
		}
		if ($mode === ImageInterface::THUMBNAIL_INSET) {
			$ratio = min($ratios);
		} else {
			$ratio = max($ratios);
		}
		if ($mode === ImageInterface::THUMBNAIL_OUTBOUND) {
			if (!$imageSize->contains($size)) {
				$size = new Box(
					min($imageSize->getWidth(), $size->getWidth()),
					min($imageSize->getHeight(), $size->getHeight())
				);
			} else {
				$imageSize = $this->_image->getSize()->scale($ratio);
				$this->_image->resize($imageSize, $filter);
			}
			$this->_image->crop(new Point(
				max(0, round(($imageSize->getWidth() - $size->getWidth()) / 2)),
				max(0, round(($imageSize->getHeight() - $size->getHeight()) / 2))
			), $size);
		} else {
			if (!$imageSize->contains($size)) {
				$imageSize = $imageSize->scale($ratio);
				$this->_image->resize($imageSize, $filter);
			} else {
				$imageSize = $this->_image->getSize()->scale($ratio);
				$this->_image->resize($imageSize, $filter);
			}
		}

		return $this;
	}
public function thumbnail ( array $ options = [ ] ) { if ( empty ( $ options [ 'height' ] ) || empty ( $ options [ 'width' ] ) ) { throw new \ InvalidArgumentException ( __d ( 'imagine' , 'You have to pass height and width in the options!' ) ) ; } $ mode = ImageInterface :: THUMBNAIL_INSET ; if ( isset ( $ options [ 'mode' ] ) && $ options [ 'mode' ] === 'outbound' ) { $ mode = ImageInterface :: THUMBNAIL_OUTBOUND ; } $ filter = ImageInterface :: FILTER_UNDEFINED ; if ( isset ( $ options [ 'filter' ] ) ) { $ filter = $ options [ 'filter' ] ; } $ size = new Box ( $ options [ 'width' ] , $ options [ 'height' ] ) ; $ imageSize = $ this -> _image -> getSize ( ) ; $ ratios = array ( $ size -> getWidth ( ) / $ imageSize -> getWidth ( ) , $ size -> getHeight ( ) / $ imageSize -> getHeight ( ) ) ; // if target width is larger than image width // AND target height is longer than image height if ( $ size -> contains ( $ imageSize ) ) { return $ this -> _image ; } if ( $ mode === ImageInterface :: THUMBNAIL_INSET ) { $ ratio = min ( $ ratios ) ; } else { $ ratio = max ( $ ratios ) ; } if ( $ mode === ImageInterface :: THUMBNAIL_OUTBOUND ) { if ( ! $ imageSize -> contains ( $ size ) ) { $ size = new Box ( min ( $ imageSize -> getWidth ( ) , $ size -> getWidth ( ) ) , min ( $ imageSize -> getHeight ( ) , $ size -> getHeight ( ) ) ) ; } else { $ imageSize = $ this -> _image -> getSize ( ) -> scale ( $ ratio ) ; $ this -> _image -> resize ( $ imageSize , $ filter ) ; } $ this -> _image -> crop ( new Point ( max ( 0 , round ( ( $ imageSize -> getWidth ( ) - $ size -> getWidth ( ) ) / 2 ) ) , max ( 0 , round ( ( $ imageSize -> getHeight ( ) - $ size -> getHeight ( ) ) / 2 ) ) ) , $ size ) ; } else { if ( ! $ imageSize -> contains ( $ size ) ) { $ imageSize = $ imageSize -> scale ( $ ratio ) ; $ this -> _image -> resize ( $ imageSize , $ filter ) ; } else { $ imageSize = $ this -> _image -> getSize ( ) -> scale ( $ ratio ) ; $ this -> _image -> resize ( $ imageSize , $ filter ) ; } } return $ this ; }
Wrapper for Imagines thumbnail.

This method had a bunch of issues and the code inside the method is a
workaround! Please see:

@link https://github.com/burzum/cakephp-imagine-plugin/issues/42
@link https://github.com/avalanche123/Imagine/issues/478

@throws \InvalidArgumentException
@param array Array of options for processing the image.
@throws InvalidArgumentException if no height or width was passed
@return $this
Wrapper for Imagines thumbnail .