Sulu\Bundle\MediaBundle\Media\ImageConverter\ImageConverterInterface::convert PHP Method

convert() public method

Convert an image and return the tmpPath.
public convert ( FileVersion $fileVersion, string $formatKey ) : Imagine\Image\ImageInterface
$fileVersion Sulu\Bundle\MediaBundle\Entity\FileVersion
$formatKey string
return Imagine\Image\ImageInterface
    public function convert(FileVersion $fileVersion, $formatKey);

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function returnImage($id, $formatKey)
 {
     $setExpireHeaders = false;
     try {
         $media = $this->mediaRepository->findMediaByIdForRendering($id, $formatKey);
         if (!$media) {
             throw new ImageProxyMediaNotFoundException('Media was not found');
         }
         $fileVersion = $this->getLatestFileVersion($media);
         if (!$this->checkMimeTypeSupported($fileVersion->getMimeType())) {
             throw new InvalidMimeTypeForPreviewException($fileVersion->getMimeType());
         }
         // Convert Media to format.
         $responseContent = $this->converter->convert($fileVersion, $formatKey);
         // HTTP Headers
         $status = 200;
         $setExpireHeaders = true;
         $finfo = new \finfo(FILEINFO_MIME_TYPE);
         $mimeType = $finfo->buffer($responseContent);
         // Save image.
         if ($this->saveImage) {
             $this->formatCache->save($responseContent, $media->getId(), $this->replaceExtension($fileVersion->getName(), $mimeType), $fileVersion->getStorageOptions(), $formatKey);
         }
     } catch (MediaException $e) {
         $responseContent = null;
         $status = 404;
         $mimeType = null;
     }
     // Set header.
     $headers = $this->getResponseHeaders($mimeType, $setExpireHeaders);
     // Return image.
     return new Response($responseContent, $status, $headers);
 }
All Usage Examples Of Sulu\Bundle\MediaBundle\Media\ImageConverter\ImageConverterInterface::convert
ImageConverterInterface