/**
  * {@inheritdoc}
  */
 public function find($path)
 {
     if ($this->filesystem->has($path) === false) {
         throw new NotLoadableException(sprintf('Source image "%s" not found.', $path));
     }
     $mimeType = $this->filesystem->getMimetype($path);
     return new Binary($this->filesystem->read($path), $mimeType, $this->extensionGuesser->guess($mimeType));
 }
Пример #2
0
 public function find($path)
 {
     try {
         $binaryFile = $this->ioService->loadBinaryFile($path);
     } catch (NotFoundException $e) {
         throw new NotLoadableException("Source image not found in {$path}", 0, $e);
     }
     $mimeType = $binaryFile->mimeType;
     return new Binary($this->ioService->getFileContents($binaryFile), $mimeType, $this->extensionGuesser->guess($mimeType));
 }
 /**
  * {@inheritDoc}
  */
 public function find($path)
 {
     if (false !== strpos($path, '../')) {
         throw new NotLoadableException(sprintf("Source image was searched with '%s' out side of the defined root path", $path));
     }
     $absolutePath = $this->rootPath . '/' . ltrim($path, '/');
     if (false == file_exists($absolutePath)) {
         throw new NotLoadableException(sprintf('Source image not found in "%s"', $absolutePath));
     }
     $mimeType = $this->mimeTypeGuesser->guess($absolutePath);
     return new Binary(file_get_contents($absolutePath), $mimeType, $this->extensionGuesser->guess($mimeType));
 }
Пример #4
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));
 }
Пример #5
0
 public function find($path)
 {
     try {
         $binaryFile = $this->ioService->loadBinaryFile($path);
         // Treat a MissingBinaryFile as a not loadable file.
         if ($binaryFile instanceof MissingBinaryFile) {
             throw new NotLoadableException("Source image not found in {$path}");
         }
         $mimeType = $this->ioService->getMimeType($path);
         return new Binary($this->ioService->getFileContents($binaryFile), $mimeType, $this->extensionGuesser->guess($mimeType));
     } catch (NotFoundException $e) {
         throw new NotLoadableException("Source image not found in {$path}", 0, $e);
     }
 }
Пример #6
0
 /**
  * {@inheritDoc}
  */
 public function find($path)
 {
     if (false !== strpos($path, '../')) {
         throw new NotLoadableException(sprintf("Source image was searched with '%s' out side of the defined root path", $path));
     }
     if (false == @getimagesize($path)) {
         throw new NotLoadableException(sprintf('Source image not found in "%s"', $path));
     }
     $tmpFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . basename($path);
     file_put_contents($tmpFilePath, file_get_contents($path));
     $mimeType = $this->mimeTypeGuesser->guess($tmpFilePath);
     unlink($tmpFilePath);
     return new Binary(file_get_contents($path), $mimeType, $this->extensionGuesser->guess($mimeType));
 }
Пример #7
0
 /**
  * @param Media $media
  *
  * @throws \RuntimeException when the file does not exist
  */
 public function prepareMedia(Media $media)
 {
     if (null === $media->getUuid()) {
         $uuid = uniqid();
         $media->setUuid($uuid);
     }
     $content = $media->getContent();
     if (empty($content)) {
         return;
     }
     if (!$content instanceof File) {
         if (!is_file($content)) {
             throw new \RuntimeException('Invalid file');
         }
         $file = new File($content);
         $media->setContent($file);
     }
     $contentType = $this->mimeTypeGuesser->guess($content->getPathname());
     if ($content instanceof UploadedFile) {
         $pathInfo = pathinfo($content->getClientOriginalName());
         if (!array_key_exists('extension', $pathInfo)) {
             $pathInfo['extension'] = $this->extensionGuesser->guess($contentType);
         }
         $media->setOriginalFilename($this->slugifier->slugify($pathInfo['filename']) . '.' . $pathInfo['extension']);
         $name = $media->getName();
         if (empty($name)) {
             $media->setName($media->getOriginalFilename());
         }
     }
     $media->setContentType($contentType);
     $media->setFileSize(filesize($media->getContent()));
     $media->setUrl($this->mediaPath . $this->getFilePath($media));
     $media->setLocation('local');
 }
Пример #8
0
    /**
     * Retrieves an image with the given filter applied.
     *
     * @param string $filter
     * @param string $path
     *
     * @throws \LogicException
     *
     * @return \Liip\ImagineBundle\Binary\BinaryInterface
     */
    public function find($filter, $path)
    {
        $loader = $this->getLoader($filter);

        $binary = $loader->find($path);
        if (!$binary instanceof BinaryInterface) {
            $mimeType = $this->mimeTypeGuesser->guess($binary);

            $binary = new Binary(
                $binary,
                $mimeType,
                $this->extensionGuesser->guess($mimeType)
            );
        }

        if (null === $binary->getMimeType()) {
            throw new \LogicException(sprintf('The mime type of image %s was not guessed.', $path));
        }

        if (0 !== strpos($binary->getMimeType(), 'image/')) {
            throw new \LogicException(sprintf('The mime type of image %s must be image/xxx got %s.', $path, $binary->getMimeType()));
        }

        return $binary;
    }
Пример #9
0
 public function postProcess($object)
 {
     if (!$object instanceof User) {
         return;
     }
     $imagePath = $object->getAvatarImage();
     // No image given, bail out
     if (empty($imagePath)) {
         return;
     }
     $fullPath = "{$this->vendorBaseDir}/{$imagePath}";
     // Image doesn't exist, bail out
     if (!file_exists($fullPath)) {
         return;
     }
     $mimeType = $this->mimeTypeGuesser->guess($fullPath);
     $image = new Binary(file_get_contents($fullPath), $mimeType, $this->extensionGuesser->guess($mimeType));
     $avatarImage = $this->userService->storeImageAsAvatar($image);
     $object->setAvatarImage($avatarImage);
 }