Exemplo n.º 1
0
 /**
  *	Resizes image.
  *	@access		public
  *	@param		integer		$width			New width
  *	@param		integer		$height			New height
  *	@param		boolean		$interpolate	Flag: use interpolation
  *	@return		object		Processor object for chaining
  *	@throws		InvalidArgumentException if width is not an integer value
  *	@throws		InvalidArgumentException if height is not an integer value
  *	@throws		OutOfRangeException if width is lower than 1
  *	@throws		OutOfRangeException if height is lower than 1
  *	@throws		OutOfRangeException if resulting image has more mega pixels than allowed
  */
 public function resize($width, $height, $interpolate = TRUE)
 {
     if (!is_int($width)) {
         throw new \InvalidArgumentException('Width must be integer');
     }
     if (!is_int($height)) {
         throw new \InvalidArgumentException('Height must be integer');
     }
     if ($width < 1) {
         throw new \OutOfRangeException('Width must be atleast 1');
     }
     if ($height < 1) {
         throw new \OutOfRangeException('Height must be atleast 1');
     }
     if ($this->image->getWidth() == $width && $this->image->getHeight() == $height) {
         return $this;
     }
     if ($this->maxMegaPixels && $width * $height > $this->maxMegaPixels * 1024 * 1024) {
         throw new \OutOfRangeException('Larger than ' . $this->maxMegaPixels . 'MP (' . $width . 'x' . $height . ')');
     }
     $image = new \CeusMedia\Image\Image();
     $image->create($width, $height);
     $image->setType($this->image->getType());
     $parameters = array_merge(array($image->getResource(), $this->image->getResource()), array(0, 0, 0, 0), array($width, $height), array($this->image->getWidth(), $this->image->getHeight()));
     $function = $interpolate ? 'imagecopyresampled' : 'imagecopyresized';
     //  function to use depending on interpolation
     $reflection = new \ReflectionFunction($function);
     //  reflect function
     $reflection->invokeArgs($parameters);
     //  call function with parameters
     $this->image->setResource($image->getResource());
     //  replace held image resource object by result
     return $this;
 }