/**
  * create Font via Python with FontForge
  *
  * @param int $fontUid
  * @param object $currentFont
  * @return array
  */
 public static function createFont($fontUid, $currentFont)
 {
     // general vars
     $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fontawesomeplus']);
     $pathToPythonBin = escapeshellarg($extConf['pathToPython']);
     $pathToScript = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('fontawesomeplus') . 'Resources/Private/Python/fontawesomeplus.py';
     $iconRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\FileRepository::class);
     $iconReferences = $iconRepository->findByRelation('tx_fontawesomeplus_domain_model_font', 'icons', $fontUid);
     $svgArray = array();
     foreach ($iconReferences as $key => $value) {
         $svgArray[$key] = PATH_site . 'fileadmin' . $value->getIdentifier();
     }
     $unicodeArray = array();
     $i = hexdec(self::HEXADECIMAL);
     foreach ($svgArray as $key => $value) {
         $unicodeArray[$key] = $i . ',uni' . dechex($i);
         $i++;
     }
     $fontPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('fontawesomeplus') . 'Resources/Public/Contrib/' . self::FACONTRIB . '/fonts/fontawesome-webfont.svg';
     $fontForgeArray = CommandUtility::escapeShellArgument(json_encode(array_combine($svgArray, $unicodeArray), JSON_UNESCAPED_SLASHES));
     $fontName = strtolower(preg_replace(array('/\\s+/', '/[^a-zA-Z0-9]/'), array('-', ''), $currentFont->getTitle()));
     $comment = CommandUtility::escapeShellArgument(str_replace(array("\r\n", "\n", "\r"), ' ', $currentFont->getDescription()));
     $copyright = CommandUtility::escapeShellArgument('netweiser');
     $version = CommandUtility::escapeShellArgument($currentFont->getVersion());
     GeneralUtility::mkdir_deep(PATH_site . 'fileadmin/' . $currentFont->getDestination(), $fontName . '/fonts/');
     $savedir = PATH_site . 'fileadmin/' . $currentFont->getDestination() . $fontName . '/fonts/';
     CommandUtility::exec("{$pathToPythonBin} {$pathToScript} {$fontPath} {$fontForgeArray} {$fontName} {$comment} {$copyright} {$version} {$savedir} 2>&1", $feedback, $returnCode);
     if ((int) $returnCode !== 0) {
         return $feedback;
     }
 }
 /**
  * get Content of DOC file
  * @param string $file
  * @return string The extracted content of the file
  */
 public function getContent($file)
 {
     // create the tempfile which will contain the content
     $tempFileName = GeneralUtility::tempnam('xls_files-Indexer');
     // Delete if exists, just to be safe.
     @unlink($tempFileName);
     // generate and execute the pdftotext commandline tool
     $fileEscaped = CommandUtility::escapeShellArgument($file);
     $cmd = "{$this->app['xls2csv']} -c ' ' -q 0 -s8859-1 -dutf-8 {$fileEscaped} > {$tempFileName}";
     CommandUtility::exec($cmd);
     // check if the tempFile was successfully created
     if (@is_file($tempFileName)) {
         $content = GeneralUtility::getUrl($tempFileName);
         unlink($tempFileName);
     } else {
         return false;
     }
     // check if content was found
     if (strlen($content)) {
         return $content;
     } else {
         return false;
     }
 }
 /**
  * Executes an ImageMagick "combine" (or composite in newer times) on four filenames - $input, $overlay and $mask as input files and $output as the output filename (written to)
  * Can be used for many things, mostly scaling and effects.
  *
  * @param string $input The relative (to PATH_site) image filepath, bottom file
  * @param string $overlay The relative (to PATH_site) image filepath, overlay file (top)
  * @param string $mask The relative (to PATH_site) image filepath, the mask file (grayscale)
  * @param string $output The relative (to PATH_site) image filepath, output filename (written to)
  * @return string
  */
 public function combineExec($input, $overlay, $mask, $output)
 {
     if ($this->NO_IMAGE_MAGICK) {
         return '';
     }
     $theMask = $this->randomName() . '.' . $this->gifExtension;
     // +matte = no alpha layer in output
     $this->imageMagickExec($mask, $theMask, '-colorspace GRAY +matte');
     $parameters = '-compose over +matte ' . CommandUtility::escapeShellArgument($input) . ' ' . CommandUtility::escapeShellArgument($overlay) . ' ' . CommandUtility::escapeShellArgument($theMask) . ' ' . CommandUtility::escapeShellArgument($output);
     $cmd = GeneralUtility::imageMagickCommand('combine', $parameters);
     $this->IM_commands[] = array($output, $cmd);
     $ret = CommandUtility::exec($cmd);
     // Change the permissions of the file
     GeneralUtility::fixPermissions($output);
     if (is_file($theMask)) {
         @unlink($theMask);
     }
     return $ret;
 }
 /**
  * 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']['im']) {
             $parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'] . ' ' . CommandUtility::escapeShellArgument($originalFileName) . '[0] ' . CommandUtility::escapeShellArgument($targetFilePath);
             $cmd = GeneralUtility::imageMagickCommand('convert', $parameters) . ' 2>&1';
             CommandUtility::exec($cmd);
             if (!file_exists($targetFilePath)) {
                 // Create a error gif
                 $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
                 $graphicalFunctions->getTemporaryImageWithText($targetFilePath, 'No thumb', 'generated!', $file->getName());
             }
         }
         $result = array('filePath' => $targetFilePath);
     }
     return $result;
 }
 /**
  * execute commandline tool pdfinfo to extract pdf informations from file
  * @param string $file
  * @return array The pdf informations as array
  */
 public function getPdfInfo($file)
 {
     if ($this->fileInfo->getIsFile() && $this->fileInfo->getExtension() == 'pdf' && $this->isAppArraySet) {
         $fileEscaped = CommandUtility::escapeShellArgument($file);
         $cmd = "{$this->app['pdfinfo']} {$fileEscaped}";
         CommandUtility::exec($cmd, $pdfInfoArray);
         $pdfInfo = $this->splitPdfInfo($pdfInfoArray);
         return $pdfInfo;
     }
     return false;
 }
Exemple #6
0
 /**
  * Create the thumbnail
  * Will exit before return if all is well.
  *
  * @return void
  */
 public function main()
 {
     // Clean output buffer to ensure no extraneous output exists
     ob_clean();
     // If file exists, we make a thumbnail of the file.
     if (is_object($this->image)) {
         // Check file extension:
         if ($this->image->getExtension() == 'ttf') {
             // Make font preview... (will not return)
             $this->fontGif($this->image);
         } elseif ($this->image->getType() != File::FILETYPE_IMAGE && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $this->image->getExtension())) {
             $this->errorGif('Not imagefile!', 'No ext!', $this->image->getName());
         }
         // ... so we passed the extension test meaning that we are going to make a thumbnail here:
         // default
         if (!$this->size) {
             $this->size = $this->sizeDefault;
         }
         // I added extra check, so that the size input option could not be fooled to pass other values.
         // That means the value is exploded, evaluated to an integer and the imploded to [value]x[value].
         // Furthermore you can specify: size=340 and it'll be translated to 340x340.
         // explodes the input size (and if no "x" is found this will add size again so it is the same for both dimensions)
         $sizeParts = explode('x', $this->size . 'x' . $this->size);
         // Cleaning it up, only two parameters now.
         $sizeParts = array(MathUtility::forceIntegerInRange($sizeParts[0], 1, 1000), MathUtility::forceIntegerInRange($sizeParts[1], 1, 1000));
         // Imploding the cleaned size-value back to the internal variable
         $this->size = implode('x', $sizeParts);
         // Getting max value
         $sizeMax = max($sizeParts);
         // Init
         $outpath = PATH_site . $this->outdir;
         // Should be - ? 'png' : 'gif' - , but doesn't work (ImageMagick prob.?)
         // René: png work for me
         $thmMode = MathUtility::forceIntegerInRange($GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails_png'], 0);
         $outext = $this->image->getExtension() != 'jpg' || $thmMode & Permission::PAGE_EDIT ? $thmMode & 1 ? 'png' : 'gif' : 'jpg';
         $outfile = 'tmb_' . substr(md5($this->image->getName() . $this->mtime . $this->size), 0, 10) . '.' . $outext;
         $this->output = $outpath . $outfile;
         if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
             // If thumbnail does not exist, we generate it
             if (!file_exists($this->output)) {
                 $parameters = '-sample ' . $this->size . ' ' . CommandUtility::escapeShellArgument($this->image->getForLocalProcessing(FALSE)) . '[0] ' . CommandUtility::escapeShellArgument($this->output);
                 $cmd = GeneralUtility::imageMagickCommand('convert', $parameters);
                 \TYPO3\CMS\Core\Utility\CommandUtility::exec($cmd);
                 if (!file_exists($this->output)) {
                     $this->errorGif('No thumb', 'generated!', $this->image->getName());
                 } else {
                     GeneralUtility::fixPermissions($this->output);
                 }
             }
             // The thumbnail is read and output to the browser
             if ($fd = @fopen($this->output, 'rb')) {
                 $fileModificationTime = filemtime($this->output);
                 header('Content-Type: image/' . ($outext === 'jpg' ? 'jpeg' : $outext));
                 header('Last-Modified: ' . date('r', $fileModificationTime));
                 header('ETag: ' . md5($this->output) . '-' . $fileModificationTime);
                 // Expiration time is chosen arbitrary to 1 month
                 header('Expires: ' . date('r', $fileModificationTime + 30 * 24 * 60 * 60));
                 fpassthru($fd);
                 fclose($fd);
             } else {
                 $this->errorGif('Read problem!', '', $this->output);
             }
         } else {
             die;
         }
     } else {
         $this->errorGif('No valid', 'inputfile!', basename($this->image));
     }
 }