/** * @return string */ public function render() { $path = GeneralUtility::getFileAbsFileName($this->arguments['path']); if (FALSE === file_exists($path)) { return NULL; } $density = $this->arguments['density']; $rotate = $this->arguments['rotate']; $page = intval($this->arguments['page']); $background = $this->arguments['background']; $forceOverwrite = (bool) $this->arguments['forceOverwrite']; $width = $this->arguments['width']; $height = $this->arguments['height']; $minWidth = $this->arguments['minWidth']; $minHeight = $this->arguments['minHeight']; $maxWidth = $this->arguments['maxWidth']; $maxHeight = $this->arguments['maxHeight']; $filename = basename($path); $pageArgument = $page > 0 ? $page - 1 : 0; $colorspace = TRUE === isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace']) ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'] : 'RGB'; $destination = GeneralUtility::getFileAbsFileName('typo3temp/vhs-pdf-' . $filename . '-page' . $page . '.png'); if (FALSE === file_exists($destination) || TRUE === $forceOverwrite) { $arguments = '-colorspace ' . $colorspace; if (0 < intval($density)) { $arguments .= ' -density ' . $density; } if (0 !== intval($rotate)) { $arguments .= ' -rotate ' . $rotate; } $arguments .= ' "' . $path . '"[' . $pageArgument . ']'; if (NULL !== $background) { $arguments .= ' -background "' . $background . '" -flatten'; } $arguments .= ' "' . $destination . '"'; $command = CommandUtility::imageMagickCommand('convert', $arguments); CommandUtility::exec($command); } $image = substr($destination, strlen(PATH_site)); return parent::render($image, $width, $height, $minWidth, $minHeight, $maxWidth, $maxHeight); }
/** * @return string */ public function render() { $src = GeneralUtility::getFileAbsFileName($this->arguments['src']); if (false === file_exists($src)) { return null; } $density = $this->arguments['density']; $rotate = $this->arguments['rotate']; $page = (int) $this->arguments['page']; $background = $this->arguments['background']; $forceOverwrite = (bool) $this->arguments['forceOverwrite']; $filename = basename($src); $pageArgument = $page > 0 ? $page - 1 : 0; if (isset($GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'])) { $colorspace = $GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace']; } else { $colorspace = 'RGB'; } $path = GeneralUtility::getFileAbsFileName('typo3temp/vhs-pdf-' . $filename . '-page' . $page . '.png'); if (false === file_exists($path) || true === $forceOverwrite) { $arguments = '-colorspace ' . $colorspace; if (0 < (int) $density) { $arguments .= ' -density ' . $density; } if (0 !== (int) $rotate) { $arguments .= ' -rotate ' . $rotate; } $arguments .= ' "' . $src . '"[' . $pageArgument . ']'; if (null !== $background) { $arguments .= ' -background "' . $background . '" -flatten'; } $arguments .= ' "' . $path . '"'; $command = CommandUtility::imageMagickCommand('convert', $arguments); CommandUtility::exec($command); } $this->preprocessImage($path); return $this->renderTag(); }
/** * Compile the command for running ImageMagick/GraphicsMagick. * * @param string $command Command to be run: identify, convert or combine/composite * @param string $parameters The parameters string * @param string $path Override the default path (e.g. used by the install tool) * @return string Compiled command that deals with IM6 & GraphicsMagick */ public static function imageMagickCommand($command, $parameters, $path = '') { return \TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand($command, $parameters, $path); }
/** * Compile the command for running ImageMagick/GraphicsMagick. * * @param string $command Command to be run: identify, convert or combine/composite * @param string $parameters The parameters string * @param string $path Override the default path (e.g. used by the install tool) * @return string Compiled command that deals with ImageMagick & GraphicsMagick * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9. - use CommandUtility directly */ public static function imageMagickCommand($command, $parameters, $path = '') { self::logDeprecatedFunction(); return CommandUtility::imageMagickCommand($command, $parameters, $path); }
/** * Determine ImageMagick / GraphicsMagick version * * @return string Version */ protected function determineImageMagickVersion() { $command = \TYPO3\CMS\Core\Utility\CommandUtility::imageMagickCommand('identify', '-version'); \TYPO3\CMS\Core\Utility\CommandUtility::exec($command, $result); $string = $result[0]; list(, $version) = explode('Magick', $string); list($version) = explode(' ', trim($version)); return trim($version); }
/** * Compile the command for running ImageMagick/GraphicsMagick. * * @param string $command Command to be run: identify, convert or combine/composite * @param string $parameters The parameters string * @param string $path Override the default path (e.g. used by the install tool) * @return string Compiled command that deals with IM6 & GraphicsMagick */ public static function imageMagickCommand($command, $parameters, $path = '') { return CommandUtility::imageMagickCommand($command, $parameters, $path); }
/** * Returns filename of the png/gif version of the input file (which can be png or gif). * If input file type does not match the wanted output type a conversion is made and temp-filename returned. * * @param string $theFile Filepath of image file * @param bool $output_png If TRUE, then input file is converted to PNG, otherwise to GIF * @return string|NULL If the new image file exists, its filepath is returned */ public static function readPngGif($theFile, $output_png = false) { if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_enabled'] || !@is_file($theFile)) { return null; } $ext = strtolower(substr($theFile, -4, 4)); if ((string) $ext == '.png' && $output_png || (string) $ext == '.gif' && !$output_png) { return $theFile; } if (!@is_dir(PATH_site . 'typo3temp/assets/images/')) { GeneralUtility::mkdir_deep(PATH_site . 'typo3temp/assets/images/'); } $newFile = PATH_site . 'typo3temp/assets/images/' . md5($theFile . '|' . filemtime($theFile)) . ($output_png ? '.png' : '.gif'); $cmd = CommandUtility::imageMagickCommand('convert', '"' . $theFile . '" "' . $newFile . '"', $GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_path']); CommandUtility::exec($cmd); if (@is_file($newFile)) { GeneralUtility::fixPermissions($newFile); return $newFile; } return null; }
/** * Generates a preview for a file * * @param File $file The source file * @param array $configuration Processing configuration * @param string $targetFilePath Output file path * @return array|NULL */ protected function generatePreviewFromFile(File $file, array $configuration, $targetFilePath) { $originalFileName = $file->getForLocalProcessing(false); // Check file extension if ($file->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $file->getExtension())) { // Create a default image $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class); $graphicalFunctions->getTemporaryImageWithText($targetFilePath, 'Not imagefile!', 'No ext!', $file->getName()); $result = array('filePath' => $targetFilePath); } elseif ($file->getExtension() === 'svg') { /** @var $gifBuilder \TYPO3\CMS\Frontend\Imaging\GifBuilder */ $gifBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class); $gifBuilder->init(); $gifBuilder->absPrefix = PATH_site; $info = $gifBuilder->getImageDimensions($originalFileName); $newInfo = $gifBuilder->getImageScale($info, $configuration['width'], $configuration['height'], array()); $result = array('width' => $newInfo[0], 'height' => $newInfo[1], 'filePath' => ''); } else { // Create the temporary file if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_enabled']) { $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . CommandUtility::escapeShellArgument($originalFileName) . '[0] ' . CommandUtility::escapeShellArgument($targetFilePath); $cmd = CommandUtility::imageMagickCommand('convert', $parameters) . ' 2>&1'; CommandUtility::exec($cmd); if (!file_exists($targetFilePath)) { // Create an error gif $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class); $graphicalFunctions->getTemporaryImageWithText($targetFilePath, 'No thumb', 'generated!', $file->getName()); } } $result = array('filePath' => $targetFilePath); } return $result; }
/** * @param string $originalFileName * @param string $temporaryFileName * @param array $configuration */ protected function resizeImage($originalFileName, $temporaryFileName, $configuration) { // Create the temporary file if (empty($GLOBALS['TYPO3_CONF_VARS']['GFX']['processor_enabled'])) { return; } if (file_exists($originalFileName)) { $arguments = CommandUtility::escapeShellArguments(['width' => $configuration['width'], 'height' => $configuration['height'], 'originalFileName' => $originalFileName, 'temporaryFileName' => $temporaryFileName]); $parameters = '-sample ' . $arguments['width'] . 'x' . $arguments['height'] . ' ' . $arguments['originalFileName'] . '[0] ' . $arguments['temporaryFileName']; $cmd = CommandUtility::imageMagickCommand('convert', $parameters) . ' 2>&1'; CommandUtility::exec($cmd); } if (!file_exists($temporaryFileName)) { // Create a error image $graphicalFunctions = $this->getGraphicalFunctionsObject(); $graphicalFunctions->getTemporaryImageWithText($temporaryFileName, 'No thumb', 'generated!', basename($originalFileName)); } }