Example #1
0
 /**
  * {@inheritDoc}
  *
  * @throws \InvalidArgumentException If field value is not an instance of \eZ\Publish\Core\FieldType\Image\Value.
  * @throws \eZ\Publish\Core\MVC\Exception\SourceImageNotFoundException If source image cannot be found.
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidVariationException If a problem occurs with generated variation.
  */
 public function getVariation(Field $field, VersionInfo $versionInfo, $variationName, array $parameters = array())
 {
     /** @var \eZ\Publish\Core\FieldType\Image\Value $imageValue */
     $imageValue = $field->value;
     $fieldId = $field->id;
     $fieldDefIdentifier = $field->fieldDefIdentifier;
     if (!$this->supportsValue($imageValue)) {
         throw new InvalidArgumentException("Value for field #{$fieldId} ({$fieldDefIdentifier}) cannot be used for image alias generation.");
     }
     $originalPath = $imageValue->id;
     try {
         $originalBinary = $this->dataLoader->find($originalPath);
     } catch (NotLoadableException $e) {
         throw new SourceImageNotFoundException($originalPath, 0, $e);
     }
     // Create the image alias only if it does not already exist.
     if ($variationName !== IORepositoryResolver::VARIATION_ORIGINAL && !$this->ioResolver->isStored($originalPath, $variationName)) {
         if ($this->logger) {
             $this->logger->debug("Generating '{$variationName}' variation on {$originalPath}, field #{$fieldId} ({$fieldDefIdentifier})");
         }
         $this->ioResolver->store($this->applyFilter($originalBinary, $variationName), $originalPath, $variationName);
     } else {
         if ($this->logger) {
             $this->logger->debug("'{$variationName}' variation on {$originalPath} is already generated. Loading from cache.");
         }
     }
     try {
         $aliasInfo = new SplFileInfo($this->ioResolver->resolve($originalPath, $variationName));
     } catch (NotResolvableException $e) {
         throw new InvalidVariationException($variationName, 'image', 0, $e);
     }
     return new ImageVariation(array('name' => $variationName, 'fileName' => $aliasInfo->getFilename(), 'dirPath' => $aliasInfo->getPath(), 'uri' => $aliasInfo->getPathname(), 'imageId' => $imageValue->imageId));
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function find($path)
 {
     $s3Url = $this->client->getObjectUrl($this->bucket, trim($this->prefix, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR));
     if (false == @getimagesize($s3Url)) {
         return $this->fallbackLoader->find($path);
     }
     $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . basename($s3Url);
     file_put_contents($tmpFilePath, file_get_contents($s3Url));
     $mimeType = $this->mimeTypeGuesser->guess($tmpFilePath);
     unlink($tmpFilePath);
     return new Binary(file_get_contents($s3Url), $mimeType, $this->extensionGuesser->guess($mimeType));
 }