Exemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see Classes/Domain/ImageProcessing/Tx_Yag_Domain_ImageProcessing_AbstractProcessor::processFile()
  */
 protected function processFile(Tx_Yag_Domain_Configuration_Image_ResolutionConfig $resolutionConfiguration, Tx_Yag_Domain_Model_Item $origFile, Tx_Yag_Domain_Model_ResolutionFileCache $resolutionFile)
 {
     if (TYPO3_MODE === 'BE') {
         $this->simulateFrontendEnvironment();
     }
     // check if the item has a source uri set
     if (trim($origFile->getSourceuri()) == '') {
         throw new Tx_Yag_Exception_InvalidPath('No Source URI set for Item ' . $origFile->getUid(), 1357896895);
     }
     $expectedDirectoryForOrigImage = Tx_Yag_Domain_FileSystem_Div::makePathAbsolute(Tx_Yag_Domain_FileSystem_Div::getPathFromFilePath($origFile->getSourceuri()));
     $sourcePathAndFileName = $origFile->getSourceuri();
     // check for source directory to be existing
     if (!file_exists($expectedDirectoryForOrigImage)) {
         // we "re-create" missing directory so that file-not-found can be handled correctly
         // even if the directory has been deleted (by accident) and we can display
         // a file-not-found image instead of an Exception
         if (!mkdir($expectedDirectoryForOrigImage, 0777, true)) {
             throw new Exception('Tried to create new directory ' . $expectedDirectoryForOrigImage . ' but could not create this directory!', 1345272425);
         }
     }
     // check for source file to be existing
     if (!file_exists(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($sourcePathAndFileName)) || !is_readable(Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($sourcePathAndFileName))) {
         // if the original image for processed image is missing, we use the file-not-found file as source
         $sourcePathAndFileName = $this->processorConfiguration->getConfigurationBuilder()->buildSysImageConfiguration()->getSysImageConfig('imageNotFound')->getSourceUri();
     }
     $processedFile = $this->getImageResource($origFile, $sourcePathAndFileName, $resolutionConfiguration);
     $resultImagePathAbsolute = $processedFile->getForLocalProcessing();
     $imageTarget = $this->generateAbsoluteResolutionPathAndFilename(end(explode(".", $resultImagePathAbsolute)), $origFile->getTitle());
     // check if we have a file
     if (!file_exists($resultImagePathAbsolute) || !is_file($resultImagePathAbsolute)) {
         throw new Exception(sprintf("\n\t\t\t\tTYPO3 image processor was not able to create an output image.\n\t\t\t\tSourceImagePath: %s,\n\t\t\t\tResultImagePath: %s", Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($sourcePathAndFileName), $resultImagePathAbsolute), 1300205628);
     }
     if ($resultImagePathAbsolute == $processedFile->getOriginalFile()->getForLocalProcessing()) {
         // the image was not processed, take the original file
         copy($resultImagePathAbsolute, $imageTarget);
     } else {
         rename($resultImagePathAbsolute, $imageTarget);
     }
     // Make sure, that expected image exists
     if (!file_exists($imageTarget)) {
         throw new Exception(sprintf('The result image of the image processing was not moved from the creation path %s to the expected target path %s', $resultImagePathAbsolute, Tx_Yag_Domain_FileSystem_Div::makePathAbsolute($imageTarget)), 1393382624);
     }
     // set resolutionFileObject
     $resolutionFile->setPath($imageTarget);
     $resolutionFile->setWidth($processedFile->getProperty('width'));
     $resolutionFile->setHeight($processedFile->getProperty('height'));
     if (TYPO3_MODE === 'BE') {
         $this->resetFrontendEnvironment();
     }
     return $processedFile;
 }