/**
  * @param FileProcessingService $fileProcessingService
  * @param DriverInterface $driver
  * @param ProcessedFile $processedFile
  * @param File $file
  * @param $taskType
  * @param array $configuration
  */
 public function optimizeImage(FileProcessingService $fileProcessingService, DriverInterface $driver, ProcessedFile $processedFile, File $file, $taskType, array $configuration = [])
 {
     if ($processedFile->getType() !== AbstractFile::FILETYPE_IMAGE) {
         return;
     }
     $optimizedProcessedFile = $this->processedFileRepository->findOneByOriginalFileAndTaskTypeAndConfiguration($file, $this->getTaskTypeForExtension($processedFile->getExtension()), $configuration);
     if (!$optimizedProcessedFile->isProcessed()) {
         $this->process($optimizedProcessedFile, $processedFile);
     }
     // This is a hack because we can not return the optimized file
     if ($optimizedProcessedFile->isProcessed() && $optimizedProcessedFile->getIdentifier() !== '') {
         ObjectAccess::setProperty($processedFile, 'name', $optimizedProcessedFile->getName(), TRUE);
         ObjectAccess::setProperty($processedFile, 'identifier', $optimizedProcessedFile->getIdentifier(), TRUE);
         $properties = $processedFile->getProperties();
         $properties['width'] = $optimizedProcessedFile->getProperty('width');
         $properties['height'] = $optimizedProcessedFile->getProperty('height');
         ObjectAccess::setProperty($processedFile, 'properties', $properties, TRUE);
     }
 }
示例#2
0
 /**
  * Returns the filename
  *
  * @return string
  */
 public function getTargetFilename()
 {
     return $this->targetFile->getNameWithoutExtension() . '_' . $this->getConfigurationChecksum() . '.' . $this->targetFile->getExtension();
 }
示例#3
0
 /**
  * Calculates the compatibility values
  * This is duplicate code taken from ContentObjectRenderer::getImgResource()
  * Ideally we should get rid of this code in both places.
  *
  * @param ProcessedFile $processedImage
  * @return array
  */
 protected function getCompatibilityImageResourceValues(ProcessedFile $processedImage)
 {
     $hash = $processedImage->calculateChecksum();
     if (isset($GLOBALS['TSFE']->tmpl->fileCache[$hash])) {
         $compatibilityImageResourceValues = $GLOBALS['TSFE']->tmpl->fileCache[$hash];
     } else {
         $compatibilityImageResourceValues = array(0 => $processedImage->getProperty('width'), 1 => $processedImage->getProperty('height'), 2 => $processedImage->getExtension(), 3 => $processedImage->getPublicUrl(), 'origFile' => $processedImage->getOriginalFile()->getPublicUrl(), 'origFile_mtime' => $processedImage->getOriginalFile()->getModificationTime(), 'originalFile' => $processedImage->getOriginalFile(), 'processedFile' => $processedImage, 'fileCacheHash' => $hash);
     }
     return $compatibilityImageResourceValues;
 }
示例#4
0
 /**
  * Gets the file extension the processed file should
  * have in the filesystem.
  *
  * @return string
  */
 public function getTargetFileExtension()
 {
     return $this->targetFile->getExtension();
 }
示例#5
0
	/**
	 * Calculates the compatibility values
	 * This is duplicate code taken from ContentObjectRenderer::getImgResource()
	 * Ideally we should get rid of this code in both places.
	 *
	 * @param ProcessedFile $processedImage
	 * @return array
	 */
	protected function getCompatibilityImageResourceValues(ProcessedFile $processedImage) {
		$hash = $processedImage->calculateChecksum();
		if (isset($GLOBALS['TSFE']->tmpl->fileCache[$hash])) {
			$compatibilityImageResourceValues = $GLOBALS['TSFE']->tmpl->fileCache[$hash];
		} else {
			$compatibilityImageResourceValues = array(
				0 => $processedImage->getProperty('width'),
				1 => $processedImage->getProperty('height'),
				2 => $processedImage->getExtension(),
				3 => $processedImage->getPublicUrl(),
				'origFile' => $processedImage->getOriginalFile()->getPublicUrl(),
				'origFile_mtime' => $processedImage->getOriginalFile()->getModificationTime(),
				// This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder,
				// in order for the setup-array to create a unique filename hash.
				'originalFile' => $processedImage->getOriginalFile(),
				'processedFile' => $processedImage,
				'fileCacheHash' => $hash
			);
		}
		return $compatibilityImageResourceValues;
	}