Exemplo n.º 1
0
 /**
  * @param array $files
  * @param boolean $onlyProperties
  * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
  * @return array|NULL
  */
 public function preprocessImages($files, $onlyProperties = FALSE)
 {
     if (TRUE === empty($files)) {
         return NULL;
     }
     if ('BE' === TYPO3_MODE) {
         $this->simulateFrontendEnvironment();
     }
     $setup = array('width' => $this->arguments['width'], 'height' => $this->arguments['height'], 'minW' => $this->arguments['minWidth'], 'minH' => $this->arguments['minHeight'], 'maxW' => $this->arguments['maxWidth'], 'maxH' => $this->arguments['maxHeight'], 'treatIdAsReference' => FALSE);
     $images = array();
     foreach ($files as $file) {
         $imageInfo = $this->contentObject->getImgResource($file->getUid(), $setup);
         $GLOBALS['TSFE']->lastImageInfo = $imageInfo;
         if (FALSE === is_array($imageInfo)) {
             throw new Exception('Could not get image resource for "' . htmlspecialchars($file->getCombinedIdentifier()) . '".', 1253191060);
         }
         if ((double) substr(TYPO3_version, 0, 3) < 7.1) {
             $imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]);
         } else {
             $imageInfo[3] = GraphicalFunctions::pngToGifByImagemagick($imageInfo[3]);
         }
         $imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]);
         $GLOBALS['TSFE']->imagesOnPage[] = $imageInfo[3];
         $imageSource = $GLOBALS['TSFE']->absRefPrefix . GeneralUtility::rawUrlEncodeFP($imageInfo[3]);
         if (TRUE === $onlyProperties) {
             $file = ResourceUtility::getFileArray($file);
         }
         $images[] = array('info' => $imageInfo, 'source' => $imageSource, 'file' => $file);
     }
     if ('BE' === TYPO3_MODE) {
         $this->resetFrontendEnvironment();
     }
     return $images;
 }
Exemplo n.º 2
0
 /**
  * Render method
  *
  * @return string
  */
 public function render()
 {
     $src = $this->viewHelperVariableContainer->get(self::SCOPE, self::SCOPE_VARIABLE_SRC);
     if ('BE' === TYPO3_MODE) {
         $tsfeBackup = FrontendSimulationUtility::simulateFrontendEnvironment();
     }
     $setup = array('width' => $this->arguments['width'], 'height' => $this->arguments['height'], 'minW' => $this->arguments['minW'], 'minH' => $this->arguments['minH'], 'maxW' => $this->arguments['maxW'], 'maxH' => $this->arguments['maxH']);
     $quality = $this->arguments['quality'];
     $format = $this->arguments['format'];
     if (FALSE === empty($format)) {
         $setup['ext'] = $format;
     }
     if (0 < intval($quality)) {
         $quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75);
         $setup['params'] .= ' -quality ' . $quality;
     }
     if ('BE' === TYPO3_MODE && '../' === substr($src, 0, 3)) {
         $src = substr($src, 3);
     }
     $result = $this->contentObject->getImgResource($src, $setup);
     if ('BE' === TYPO3_MODE) {
         FrontendSimulationUtility::resetFrontendEnvironment($tsfeBackup);
     }
     $src = $this->preprocessSourceUri(rawurldecode($result[3]));
     if (NULL === $this->arguments['media']) {
         $this->viewHelperVariableContainer->addOrUpdate(self::SCOPE, self::SCOPE_VARIABLE_DEFAULT_SOURCE, $src);
     } else {
         $this->tag->addAttribute('media', $this->arguments['media']);
     }
     $this->tag->addAttribute('srcset', $src);
     return $this->tag->render();
 }
 /**
  * Resizes a given image (if required) and renders the respective img tag
  * @see http://typo3.org/documentation/document-library/references/doc_core_tsref/4.2.0/view/1/5/#id4164427
  *
  * @param string $src
  * @param string $width width of the image. This can be a numeric value representing the fixed width of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param string $height height of the image. This can be a numeric value representing the fixed height of the image in pixels. But you can also perform simple calculations by adding "m" or "c" to the value. See imgResource.width for possible options.
  * @param integer $minWidth minimum width of the image
  * @param integer $minHeight minimum height of the image
  * @param integer $maxWidth maximum width of the image
  * @param integer $maxHeight maximum height of the image
  *
  * @return string rendered tag.
  * @author Sebastian Böttger <*****@*****.**>
  * @author Bastian Waidelich <*****@*****.**>
  */
 public function render($src, $width = NULL, $height = NULL, $minWidth = NULL, $minHeight = NULL, $maxWidth = NULL, $maxHeight = NULL)
 {
     if (TYPO3_MODE === 'BE') {
         $this->simulateFrontendEnvironment();
     }
     $setup = array('width' => $width, 'height' => $height, 'minW' => $minWidth, 'minH' => $minHeight, 'maxW' => $maxWidth, 'maxH' => $maxHeight);
     $src = current(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(chr(10), $src));
     // Just get the first one, in case this came from a field of
     if (TYPO3_MODE === 'BE' && substr($src, 0, 3) === '../') {
         $src = substr($src, 3);
     }
     $imageInfo = $this->contentObject->getImgResource($src, $setup);
     $GLOBALS['TSFE']->lastImgResourceInfo = $imageInfo;
     if (!is_array($imageInfo)) {
         throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Could not get image resource for "' . htmlspecialchars($src) . '".', 1253191060);
     }
     $imageInfo[3] = \TYPO3\CMS\Core\Utility\GeneralUtility::png_to_gif_by_imagemagick($imageInfo[3]);
     $GLOBALS['TSFE']->imagesOnPage[] = $imageInfo[3];
     $imageSource = $GLOBALS['TSFE']->absRefPrefix . \TYPO3\CMS\Core\Utility\GeneralUtility::rawUrlEncodeFP($imageInfo[3]);
     if (TYPO3_MODE === 'BE') {
         $imageSource = '../' . $imageSource;
         $this->resetFrontendEnvironment();
     }
     return $imageSource;
 }
 /**
  * @test
  */
 public function getImgResourceCallsGetImgResourcePostProcessHook()
 {
     $this->templateServiceMock->expects($this->atLeastOnce())->method('getFileName')->with('typo3/clear.gif')->will($this->returnValue('typo3/clear.gif'));
     $resourceFactory = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceFactory::class, array(), array(), '', false);
     $this->subject->expects($this->any())->method('getResourceFactory')->will($this->returnValue($resourceFactory));
     $className = $this->getUniqueId('tx_coretest');
     $getImgResourceHookMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectGetImageResourceHookInterface::class, array('getImgResourcePostProcess'), array(), $className);
     $getImgResourceHookMock->expects($this->once())->method('getImgResourcePostProcess')->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
     $getImgResourceHookObjects = array($getImgResourceHookMock);
     $this->subject->_setRef('getImgResourceHookObjects', $getImgResourceHookObjects);
     $this->subject->getImgResource('typo3/clear.gif', array());
 }
Exemplo n.º 5
0
 /**
  * @throws Exception
  * @return void
  */
 public function preprocessImage()
 {
     $src = $this->arguments['src'];
     $width = $this->arguments['width'];
     $height = $this->arguments['height'];
     $minW = $this->arguments['minW'];
     $minH = $this->arguments['minH'];
     $maxW = $this->arguments['maxW'];
     $maxH = $this->arguments['maxH'];
     $format = $this->arguments['format'];
     $quality = $this->arguments['quality'];
     $treatIdAsReference = (bool) $this->arguments['treatIdAsReference'];
     if ('BE' === TYPO3_MODE) {
         $this->simulateFrontendEnvironment();
     }
     $setup = array('width' => $width, 'height' => $height, 'minW' => $minW, 'minH' => $minH, 'maxW' => $maxW, 'maxH' => $maxH, 'treatIdAsReference' => $treatIdAsReference);
     if (FALSE === empty($format)) {
         $setup['ext'] = $format;
     }
     if (0 < intval($quality)) {
         $quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75);
         $setup['params'] = '-quality ' . $quality;
     }
     if ('BE' === TYPO3_MODE && '../' === substr($src, 0, 3)) {
         $src = substr($src, 3);
     }
     $this->imageInfo = $this->contentObject->getImgResource($src, $setup);
     $GLOBALS['TSFE']->lastImageInfo = $this->imageInfo;
     if (FALSE === is_array($this->imageInfo)) {
         throw new Exception('Could not get image resource for "' . htmlspecialchars($src) . '".', 1253191060);
     }
     if ((double) substr(TYPO3_version, 0, 3) < 7.1) {
         $this->imageInfo[3] = GeneralUtility::png_to_gif_by_imagemagick($this->imageInfo[3]);
     } else {
         $this->imageInfo[3] = GraphicalFunctions::pngToGifByImagemagick($this->imageInfo[3]);
     }
     $GLOBALS['TSFE']->imagesOnPage[] = $this->imageInfo[3];
     $publicUrl = rawurldecode($this->imageInfo[3]);
     $this->mediaSource = $GLOBALS['TSFE']->absRefPrefix . GeneralUtility::rawUrlEncodeFP($publicUrl);
     if ('BE' === TYPO3_MODE) {
         $this->resetFrontendEnvironment();
     }
 }
Exemplo n.º 6
0
 /**
  * @param string|null $imageSource
  * @throws Exception
  */
 public function preprocessImage($imageSource = null)
 {
     $src = null === $imageSource ? $this->arguments['src'] : $imageSource;
     $width = $this->arguments['width'];
     $height = $this->arguments['height'];
     $minW = $this->arguments['minW'];
     $minH = $this->arguments['minH'];
     $maxW = $this->arguments['maxW'];
     $maxH = $this->arguments['maxH'];
     $format = $this->arguments['format'];
     $quality = $this->arguments['quality'];
     $treatIdAsReference = (bool) $this->arguments['treatIdAsReference'];
     $crop = $this->arguments['crop'];
     if (is_object($src) && $src instanceof FileReference) {
         $src = $src->getUid();
         $treatIdAsReference = true;
     }
     if ($crop === null) {
         $crop = is_object($src) && $src instanceof FileReference ? $src->getProperty('crop') : null;
     }
     if ('BE' === TYPO3_MODE) {
         $this->simulateFrontendEnvironment();
     }
     $setup = ['width' => $width, 'height' => $height, 'minW' => $minW, 'minH' => $minH, 'maxW' => $maxW, 'maxH' => $maxH, 'treatIdAsReference' => $treatIdAsReference, 'crop' => $crop];
     if (false === empty($format)) {
         $setup['ext'] = $format;
     }
     if (0 < (int) $quality) {
         $quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75);
         $setup['params'] = '-quality ' . $quality;
     }
     if (TYPO3_MODE === 'BE' && strpos($src, '../') === 0) {
         $src = substr($src, 3);
     }
     $this->imageInfo = $this->contentObject->getImgResource($src, $setup);
     $GLOBALS['TSFE']->lastImageInfo = $this->imageInfo;
     if (false === is_array($this->imageInfo)) {
         throw new Exception('Could not get image resource for "' . htmlspecialchars($src) . '".', 1253191060);
     }
     if ($this->hasArgument('canvasWidth') && $this->hasArgument('canvasHeight')) {
         $canvasWidth = (int) $this->arguments['canvasWidth'];
         $canvasHeight = (int) $this->arguments['canvasHeight'];
         $canvasColor = str_replace('#', '', $this->arguments['canvasColor']);
         $originalFilename = $this->imageInfo[3];
         $originalExtension = substr($originalFilename, -3);
         $destinationFilename = 'typo3temp/vhs-canvas-' . md5($originalFilename . $canvasColor . $canvasWidth . $canvasHeight) . '.' . $originalExtension;
         $destinationFilepath = GeneralUtility::getFileAbsFileName($destinationFilename);
         if (!file_exists($destinationFilepath)) {
             $arguments = sprintf('%s -background \'#%s\' -gravity center -extent %dx%d %s', $originalFilename, $canvasColor, $canvasWidth, $canvasHeight, $destinationFilepath);
             $command = CommandUtility::imageMagickCommand('convert', $arguments);
             CommandUtility::exec($command);
         }
         $this->imageInfo[3] = $destinationFilename;
     }
     $GLOBALS['TSFE']->imagesOnPage[] = $this->imageInfo[3];
     $GLOBALS['TSFE']->imagesOnPage[] = $this->imageInfo[3];
     $publicUrl = rawurldecode($this->imageInfo[3]);
     $this->mediaSource = GeneralUtility::rawUrlEncodeFP($publicUrl);
     if (TYPO3_MODE === 'BE') {
         $this->resetFrontendEnvironment();
     }
 }