Inheritance: extends Neos\Media\Domain\Model\ResourceBasedInterface
コード例 #1
0
 /**
  * The given $value is valid if it is an \Neos\Media\Domain\Model\ImageInterface of the
  * configured type (one of the image/* IANA media subtypes)
  *
  * 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 Image) {
         $this->addError('The given value was not an Image instance.', 1327947256);
         return;
     }
     $allowedImageTypes = $this->options['allowedTypes'];
     array_walk($allowedImageTypes, function (&$value) {
         $value = 'image/' . $value;
     });
     if (!in_array($image->getMediaType(), $allowedImageTypes)) {
         $this->addError('The media type "%s" is not allowed for this image.', 1327947647, array($image->getMediaType()));
     }
 }
コード例 #2
0
 /**
  * Converts and adds ImageAdjustments to the ImageVariant
  *
  * @param ImageInterface $asset
  * @param mixed $source
  * @param array $convertedChildProperties
  * @param PropertyMappingConfigurationInterface $configuration
  * @return ImageInterface|NULL
  */
 protected function applyTypeSpecificHandling($asset, $source, array $convertedChildProperties, PropertyMappingConfigurationInterface $configuration)
 {
     if ($asset instanceof ImageVariant) {
         $adjustments = [];
         if (isset($source['adjustments'])) {
             foreach ($source['adjustments'] as $adjustmentType => $adjustmentOptions) {
                 if (isset($adjustmentOptions['__type'])) {
                     $adjustmentType = $adjustmentOptions['__type'];
                     unset($adjustmentOptions['__type']);
                 }
                 $identity = null;
                 if (isset($adjustmentOptions['__identity'])) {
                     $identity = $adjustmentOptions['__identity'];
                     unset($adjustmentOptions['__identity']);
                 }
                 $adjustment = $this->propertyMapper->convert($adjustmentOptions, $adjustmentType, $configuration);
                 if ($identity !== null) {
                     ObjectAccess::setProperty($adjustment, 'persistence_object_identifier', $identity, true);
                 }
                 $adjustments[] = $adjustment;
             }
         } elseif (isset($source['processingInstructions'])) {
             $adjustments = $this->processingInstructionsConverter->convertFrom($source['processingInstructions'], 'array');
         }
         if (count($adjustments) > 0) {
             $asset->addAdjustments($adjustments);
         }
     }
     return $asset;
 }
コード例 #3
0
 /**
  * The given $value is valid if it is an \Neos\Media\Domain\Model\ImageInterface of the
  * configured orientation (square, portrait and/or landscape)
  * 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.', 1328028604);
         return;
     }
     if (!in_array($image->getOrientation(), $this->options['allowedOrientations'])) {
         if (count($this->options['allowedOrientations']) === 1) {
             reset($this->options['allowedOrientations']);
             $allowedOrientation = current($this->options['allowedOrientations']);
             $this->addError('The image orientation must be "%s".', 1328029406, array($allowedOrientation));
         } else {
             $this->addError('The image orientation "%s" is not allowed.', 1328029362, array($image->getOrientation()));
         }
     }
 }
コード例 #4
0
 /**
  * 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']));
         }
     }
 }
コード例 #5
0
 /**
  * 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());
     }
 }
コード例 #6
0
 /**
  * @param ImageInterface $thumbnail
  * @return string
  * @throws ThumbnailServiceException
  */
 public function getUriForThumbnail(ImageInterface $thumbnail)
 {
     $resource = $thumbnail->getResource();
     if ($resource) {
         return $this->resourceManager->getPublicPersistentResourceUri($resource);
     }
     $staticResource = $thumbnail->getStaticResource();
     if ($staticResource === null) {
         throw new ThumbnailServiceException(sprintf('Could not generate URI for static thumbnail "%s".', $this->persistenceManager->getIdentifierByObject($thumbnail)), 1450178437);
     }
     return $this->resourceManager->getPublicPackageResourceUriByPath($staticResource);
 }