/** * Creates crop point * * @param AbstractImage $abstractImage * @param int $width * @param int $height * * @return Point */ protected function createCropPoint(AbstractImage $abstractImage, $width, $height) { if (!is_numeric($width) || !is_numeric($height)) { throw new IcrLogicException('Provided values for width and height are not numeric!'); } $width = (int) $width; $height = (int) $height; $imageWidth = $abstractImage->getSize()->getWidth(); $imageHeight = $abstractImage->getSize()->getHeight(); if ($imageWidth < $width || $imageHeight < $height) { throw new IcrRuntimeException('Provided image is too small to be resize! Provide larger image.'); } $cropWidth = $imageWidth / 2 - $width / 2; $cropHeight = $imageHeight / 2 - $height / 2; return new Point($cropWidth, $cropHeight); }
/** * Wrapper for Imagines resize * * @param array Array of options for processing the image * @throws \InvalidArgumentException * @return $this */ public function resize(array $options = []) { if (empty($options['height']) || empty($options['width'])) { throw new \InvalidArgumentException(__d('imagine', 'You have to pass height and width in the options!')); } $this->_image->resize(new Box($options['width'], $options['height'])); return $this; }
/** * Creates crop point * * @param AbstractImage $abstractImage * @param int $width * @param int $height * * @return Point */ protected function createCropPoint(AbstractImage $abstractImage, $width, $height) { if (!is_numeric($width) || !is_numeric($height)) { throw new \LogicException('Provided values for width and height are not numeric!'); } $width = (int) $width; $height = (int) $height; $imageWidth = $abstractImage->getSize()->getWidth(); $imageHeight = $abstractImage->getSize()->getHeight(); if ($imageWidth < $width || $imageHeight < $height) { throw new ImageTooSmallException('Provided image is too small to be resize! Provide larger image.'); } $cropWidth = $imageWidth / 2 - $width / 2; $cropHeight = $imageHeight / 2 - $height / 2; $box = clone $this->box; $box->setWidth(round($cropWidth))->setHeight(round($cropHeight)); $this->point->setBox($box); return $this->point; }
/** * Test manipulate with large values */ public function testManipulateWithLargeValues() { $image = $this->scale->manipulate($this->image->open($this->path), 2000, 2000); static::assertEquals(2000, $image->getSize()->getWidth()); static::assertEquals(2000, $image->getSize()->getHeight()); }
/** * @param \Imagine\Image\AbstractImage $oImage */ private function correctImageOrientation($oImage, $bDetectImageOrientation = true, $iThumbnailBoxSize = null) { $iOrientation = 1; if ($bDetectImageOrientation && \MailSo\Base\Utils::FunctionExistsAndEnabled('exif_read_data') && \MailSo\Base\Utils::FunctionExistsAndEnabled('gd_info')) { $oMetadata = $oImage->metadata(new \Imagine\Image\Metadata\ExifMetadataReader()); $iOrientation = isset($oMetadata['ifd0.Orientation']) && is_numeric($oMetadata['ifd0.Orientation']) ? (int) $oMetadata['ifd0.Orientation'] : 1; } if ($iThumbnailBoxSize && 0 < $iThumbnailBoxSize) { $oImage = $oImage->thumbnail(new \Imagine\Image\Box($iThumbnailBoxSize, $iThumbnailBoxSize), \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND); $this->rotateImageByOrientation($oImage, $iOrientation); } else { $this->rotateImageByOrientation($oImage, $iOrientation); } return $oImage; }
/** * {@inheritdoc} */ public function manipulate(AbstractImage $image, $width, $height) { $this->box->setHeight($height)->setWidth($width); return $image->resize($this->box); }
/** * Test manipulate with large values */ public function testManipulateWithTooLargeParameters() { static::setExpectedExceptionRegExp('Todstoychev\\Icr\\Exception\\ImageTooSmallException'); $this->crop->manipulate($this->image->open($this->path), 2000, 2000); }
/** * Test manipulate with string */ public function testManipulateWithNonNumericString() { static::setExpectedExceptionRegExp('LogicException'); $this->resizeCrop->manipulate($this->image->open($this->path), 'test', 'test'); }
/** * {@inheritdoc} */ public function manipulate(AbstractImage $image, $width, $height) { return $image->resize(new Box($width, $height)); }
/** * Test manipulate with large input */ public function testManipulateWithLargeInput() { static::setExpectedExceptionRegExp('LogicException'); $this->resize->manipulate($this->image->open($this->path), 2000, 2000); }