/** * The given $value is valid if it is an \Neos\Media\Domain\Model\ImageInterface of the configured resolution * Note: a value of NULL or empty string ('') is considered valid * * @param ImageInterface $image The image that should be validated * @return void * @api */ protected function isValid($image) { $this->validateOptions(); if (!$image instanceof 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'])); } } }
/** * 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()); } }