/**
  * The given $value is valid if it is an \TYPO3\Media\Domain\Model\ImageInterface of the configured resolution
  * Note: a value of NULL or empty string ('') is considered valid
  *
  * @param \TYPO3\Media\Domain\Model\ImageInterface $image The image that should be validated
  * @return void
  * @api
  */
 protected function isValid($image)
 {
     $this->validateOptions();
     if (!$image instanceof \TYPO3\Media\Domain\Model\ImageInterface) {
         $this->addError('The given value was not an Image instance.', 1327943859);
         return;
     }
     if (isset($this->options['minimumWidth']) && $image->getWidth() < $this->options['minimumWidth']) {
         $this->addError('The actual image width of %1$d is lower than the allowed minimum width of %2$d.', 1319801362, array($image->getWidth(), $this->options['minimumWidth']));
     } elseif (isset($this->options['maximumWidth']) && $image->getWidth() > $this->options['maximumWidth']) {
         $this->addError('The actual image width of %1$d is higher than the allowed maximum width of %2$d.', 1319801859, array($image->getWidth(), $this->options['maximumWidth']));
     }
     if (isset($this->options['minimumHeight']) && $image->getHeight() < $this->options['minimumHeight']) {
         $this->addError('The actual image height of %1$d is lower than the allowed minimum height of %2$d.', 1319801925, array($image->getHeight(), $this->options['minimumHeight']));
     } elseif (isset($this->options['maximumHeight']) && $image->getHeight() > $this->options['maximumHeight']) {
         $this->addError('The actual image height of %1$d is higher than the allowed maximum height of %2$d.', 1319801929, array($image->getHeight(), $this->options['maximumHeight']));
     }
     if (isset($this->options['minimumResolution']) || isset($this->options['maximumResolution'])) {
         $resolution = $image->getWidth() * $image->getHeight();
         if (isset($this->options['minimumResolution']) && $resolution < $this->options['minimumResolution']) {
             $this->addError('The given image size of %1$d x %2$d is too low for the required minimum resolution of %3$d.', 1319813336, array($image->getHeight(), $image->getHeight(), $this->options['minimumResolution']));
         } elseif (isset($this->options['maximumResolution']) && $resolution > $this->options['maximumResolution']) {
             $this->addError('The given image size of %1$d x %2$d is too high for the required maximum resolution of %3$d.', 1319813355, array($image->getHeight(), $image->getHeight(), $this->options['maximumResolution']));
         }
     }
 }
示例#2
0
 /**
  * Calculates the dimensions of the thumbnail to be generated and returns the thumbnail image if the new dimensions
  * differ from the specified image dimensions, otherwise the original image is returned.
  *
  * @param ImageInterface $image
  * @param integer $maximumWidth
  * @param integer $maximumHeight
  * @param boolean $allowCropping
  * @param boolean $allowUpScaling
  * @return ImageInterface
  */
 protected function getImageThumbnailImage(ImageInterface $image, $maximumWidth = NULL, $maximumHeight = NULL, $allowCropping = NULL, $allowUpScaling = NULL)
 {
     $ratioMode = $allowCropping ? ImageInterface::RATIOMODE_OUTBOUND : ImageInterface::RATIOMODE_INSET;
     if ($allowUpScaling === FALSE) {
         $maximumWidth = $maximumWidth > $image->getWidth() ? $image->getWidth() : $maximumWidth;
         $maximumHeight = $maximumHeight > $image->getHeight() ? $image->getHeight() : $maximumHeight;
     }
     if ($maximumWidth === $image->getWidth() && $maximumHeight === $image->getHeight()) {
         return $image;
     }
     return $this->thumbnailService->getThumbnail($image, $maximumWidth, $maximumHeight, $ratioMode, $allowUpScaling);
 }
 /**
  * Refits the crop proportions to be the maximum size within the image boundaries.
  *
  * @param ImageInterface $image
  * @return void
  */
 public function refit(ImageInterface $image)
 {
     $this->x = 0;
     $this->y = 0;
     $ratio = $this->getWidth() / $image->getWidth();
     $this->setWidth($image->getWidth());
     $this->setHeight($this->getHeight() / $ratio);
     if ($this->getHeight() > $image->getHeight()) {
         $ratio = $this->getHeight() / $image->getHeight();
         $this->setWidth($this->getWidth() / $ratio);
         $this->setHeight($image->getHeight());
     }
 }