Exemplo n.º 1
0
 public function initializeOrUpdate()
 {
     $localCopyForCsvFile = $this->sourceFile->createTemporaryLocalCopy();
     $csvReader = Reader::createFromPath($localCopyForCsvFile);
     $csvReader->setDelimiter(';');
     $csv = $csvReader->fetchAssoc();
     $output = array();
     foreach ($csv as $row) {
         $output[] = json_encode($row);
     }
     Files::createDirectoryRecursively(dirname($this->getSourceFileName()));
     file_put_contents($this->getSourceFileName(), implode("\n", $output));
     parent::initializeOrUpdate();
 }
 /**
  * @param FlowResource $resource
  * @param MetaDataCollection $metaDataCollection
  * @throws \TYPO3\Flow\Resource\Exception
  */
 public function extractMetaData(FlowResource $resource, MetaDataCollection $metaDataCollection)
 {
     $manager = new ImageManager(['driver' => 'gd']);
     $image = $manager->make($resource->createTemporaryLocalCopy());
     $iptcData = $image->iptc();
     if (is_array($iptcData)) {
         $metaDataCollection->set('iptc', $this->buildIptcDto($iptcData));
     }
     $exifData = $image->exif();
     if (is_array($exifData)) {
         $metaDataCollection->set('exif', $this->buildExifDto($exifData));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function createTemporaryLocalCopy()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'createTemporaryLocalCopy', array());
     return parent::createTemporaryLocalCopy();
 }
 /**
  * @param FlowResource $originalResource
  * @param array $adjustments
  * @return array resource, width, height as keys
  * @throws ImageFileException
  * @throws InvalidConfigurationException
  * @throws \TYPO3\Flow\Resource\Exception
  */
 public function processImage(FlowResource $originalResource, array $adjustments)
 {
     $additionalOptions = array();
     $adjustmentsApplied = false;
     // TODO: Special handling for SVG should be refactored at a later point.
     if ($originalResource->getMediaType() === 'image/svg+xml') {
         $originalResourceStream = $originalResource->getStream();
         $resource = $this->resourceManager->importResource($originalResourceStream, $originalResource->getCollectionName());
         fclose($originalResourceStream);
         $resource->setFilename($originalResource->getFilename());
         return ['width' => null, 'height' => null, 'resource' => $resource];
     }
     $resourceUri = $originalResource->createTemporaryLocalCopy();
     $resultingFileExtension = $originalResource->getFileExtension();
     $transformedImageTemporaryPathAndFilename = $this->environment->getPathToTemporaryDirectory() . uniqid('ProcessedImage-') . '.' . $resultingFileExtension;
     if (!file_exists($resourceUri)) {
         throw new ImageFileException(sprintf('An error occurred while transforming an image: the resource data of the original image does not exist (%s, %s).', $originalResource->getSha1(), $resourceUri), 1374848224);
     }
     $imagineImage = $this->imagineService->open($resourceUri);
     if ($this->imagineService instanceof \Imagine\Imagick\Imagine && $originalResource->getFileExtension() === 'gif' && $this->isAnimatedGif(file_get_contents($resourceUri)) === true) {
         $imagineImage->layers()->coalesce();
         $layers = $imagineImage->layers();
         $newLayers = array();
         foreach ($layers as $index => $imagineFrame) {
             $imagineFrame = $this->applyAdjustments($imagineFrame, $adjustments, $adjustmentsApplied);
             $newLayers[] = $imagineFrame;
         }
         $imagineImage = array_shift($newLayers);
         $layers = $imagineImage->layers();
         foreach ($newLayers as $imagineFrame) {
             $layers->add($imagineFrame);
         }
         $additionalOptions['animated'] = true;
     } else {
         $imagineImage = $this->applyAdjustments($imagineImage, $adjustments, $adjustmentsApplied);
     }
     if ($adjustmentsApplied === true) {
         $imagineImage->save($transformedImageTemporaryPathAndFilename, $this->getOptionsMergedWithDefaults($additionalOptions));
         $imageSize = $imagineImage->getSize();
         // TODO: In the future the collectionName of the new resource should be configurable.
         $resource = $this->resourceManager->importResource($transformedImageTemporaryPathAndFilename, $originalResource->getCollectionName());
         if ($resource === false) {
             throw new ImageFileException('An error occurred while importing a generated image file as a resource.', 1413562208);
         }
         unlink($transformedImageTemporaryPathAndFilename);
         $pathInfo = UnicodeFunctions::pathinfo($originalResource->getFilename());
         $resource->setFilename(sprintf('%s-%ux%u.%s', $pathInfo['filename'], $imageSize->getWidth(), $imageSize->getHeight(), $pathInfo['extension']));
     } else {
         $originalResourceStream = $originalResource->getStream();
         $resource = $this->resourceManager->importResource($originalResourceStream, $originalResource->getCollectionName());
         fclose($originalResourceStream);
         $resource->setFilename($originalResource->getFilename());
         $imageSize = $this->getImageSize($originalResource);
         $imageSize = new Box($imageSize['width'], $imageSize['height']);
     }
     $this->imageSizeCache->set($resource->getCacheEntryIdentifier(), array('width' => $imageSize->getWidth(), 'height' => $imageSize->getHeight()));
     $result = array('width' => $imageSize->getWidth(), 'height' => $imageSize->getHeight(), 'resource' => $resource);
     return $result;
 }
Exemplo n.º 5
0
 /**
  * @ORM\PreFlush
  */
 public function writeUnsubscribeFile()
 {
     if ($this->unsubscribeFile) {
         rename($this->unsubscribeFile->createTemporaryLocalCopy(), $this->getUnsubscribeFileName());
     }
 }