/** * This method actually does the processing of files locally * * takes the original file (on remote storages this will be fetched from the remote server) * does the IM magic on the local server by creating a temporary typo3temp/ file * copies the typo3temp/ file to the processing folder of the target storage * removes the typo3temp/ file * * @param TaskInterface $task * @return array */ public function process(TaskInterface $task) { $targetFile = $task->getTargetFile(); // Merge custom configuration with default configuration $configuration = array_merge(array('width' => 64, 'height' => 64), $task->getConfiguration()); $configuration['width'] = Utility\MathUtility::forceIntegerInRange($configuration['width'], 1, 1000); $configuration['height'] = Utility\MathUtility::forceIntegerInRange($configuration['height'], 1, 1000); $originalFileName = $targetFile->getOriginalFile()->getForLocalProcessing(FALSE); // Create a temporary file in typo3temp/ if ($targetFile->getOriginalFile()->getExtension() === 'jpg') { $targetFileExtension = '.jpg'; } else { $targetFileExtension = '.png'; } // Create the thumb filename in typo3temp/preview_....jpg $temporaryFileName = Utility\GeneralUtility::tempnam('preview_') . $targetFileExtension; // Check file extension if ($targetFile->getOriginalFile()->getType() != Resource\File::FILETYPE_IMAGE && !Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $targetFile->getOriginalFile()->getExtension())) { // Create a default image $this->processor->getTemporaryImageWithText($temporaryFileName, 'Not imagefile!', 'No ext!', $targetFile->getOriginalFile()->getName()); } else { // Create the temporary file if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) { $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . $this->processor->wrapFileName($originalFileName) . '[0] ' . $this->processor->wrapFileName($temporaryFileName); $cmd = Utility\GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1'; Utility\CommandUtility::exec($cmd); if (!file_exists($temporaryFileName)) { // Create a error gif $this->processor->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', $targetFile->getOriginalFile()->getName()); } } } return array('filePath' => $temporaryFileName); }
/** * Processing the focus point crop (fallback to LocalCropScaleMaskHelper) * * @param TaskInterface $task * * @return array|NULL */ public function process(TaskInterface $task) { $configuration = $task->getConfiguration(); $crop = $configuration['crop'] ? json_decode($configuration['crop']) : null; if ($crop instanceof \stdClass && isset($crop->x)) { // if crop is enable release the process return parent::process($task); } $sourceFile = $task->getSourceFile(); try { if (self::$deepCheck === false) { self::$deepCheck = true; $ratio = $this->getCurrentRatioConfiguration(); $this->dimensionService->getRatio($ratio); $newFile = $this->focusCropService->getCroppedImageSrcByFile($sourceFile, $ratio); $file = ResourceFactory::getInstance()->retrieveFileOrFolderObject($newFile); $targetFile = $task->getTargetFile(); ObjectAccess::setProperty($targetFile, 'originalFile', $file, true); ObjectAccess::setProperty($targetFile, 'originalFileSha1', $file->getSha1(), true); ObjectAccess::setProperty($targetFile, 'storage', $file->getStorage(), true); ObjectAccess::setProperty($task, 'sourceFile', $file, true); ObjectAccess::setProperty($task, 'targetFile', $targetFile, true); } } catch (\Exception $ex) { } self::$deepCheck = false; return parent::process($task); }
/** * This method actually does the processing of files locally * * takes the original file (on remote storages this will be fetched from the remote server) * does the IM magic on the local server by creating a temporary typo3temp/ file * copies the typo3temp/ file to the processing folder of the target storage * removes the typo3temp/ file * * The returned array has the following structure: * width => 100 * height => 200 * filePath => /some/path * * If filePath isn't set but width and height are the original file is used as ProcessedFile * with the returned width and height. This is for example useful for SVG images. * * @param TaskInterface $task * @return array|NULL */ public function process(TaskInterface $task) { $sourceFile = $task->getSourceFile(); // Merge custom configuration with default configuration $configuration = array_merge(array('width' => 64, 'height' => 64), $task->getConfiguration()); $configuration['width'] = MathUtility::forceIntegerInRange($configuration['width'], 1); $configuration['height'] = MathUtility::forceIntegerInRange($configuration['height'], 1); // Do not scale up if the source file has a size and the target size is larger if ($sourceFile->getProperty('width') > 0 && $sourceFile->getProperty('height') > 0 && $configuration['width'] > $sourceFile->getProperty('width') && $configuration['height'] > $sourceFile->getProperty('height')) { return NULL; } return $this->generatePreviewFromFile($sourceFile, $configuration, $this->getTemporaryFilePath($task)); }