/** * Publishes the given persistent resource from the given storage * * @param PersistentResource $resource The resource to publish * @param CollectionInterface $collection The collection the given resource belongs to * @return void */ public function publishResource(PersistentResource $resource, CollectionInterface $collection) { $sourceStream = $resource->getStream(); if ($sourceStream === false) { $this->handleMissingData($resource, $collection); return; } $this->publishFile($sourceStream, $this->getRelativePublicationPathAndFilename($resource)); fclose($sourceStream); }
/** * Get the size of a Flow PersistentResource that contains an image file. * * @param PersistentResource $resource * @return array width and height as keys * @throws ImageFileException */ public function getImageSize(PersistentResource $resource) { $cacheIdentifier = $resource->getCacheEntryIdentifier(); $imageSize = $this->imageSizeCache->get($cacheIdentifier); if ($imageSize !== false) { return $imageSize; } // TODO: Special handling for SVG should be refactored at a later point. if ($resource->getMediaType() === 'image/svg+xml') { $imageSize = ['width' => null, 'height' => null]; } else { try { $imagineImage = $this->imagineService->read($resource->getStream()); $sizeBox = $imagineImage->getSize(); $imageSize = array('width' => $sizeBox->getWidth(), 'height' => $sizeBox->getHeight()); } catch (\Exception $e) { throw new ImageFileException(sprintf('The given resource was not an image file your choosen driver can open. The original error was: %s', $e->getMessage()), 1336662898); } } $this->imageSizeCache->set($cacheIdentifier, $imageSize); return $imageSize; }