/** * Write gif and png test * * @return \TYPO3\CMS\Install\Status\StatusInterface */ protected function writeGifAndPng() { $this->setUpDatabaseConnectionMock(); $imageProcessor = $this->initializeImageProcessor(); $parseTimeStart = GeneralUtility::milliseconds(); $testResults = array('gif' => array(), 'png' => array()); // Gif $inputFile = $this->imageBasePath . 'TestInput/Test.gif'; $imageProcessor->imageMagickConvert_forceFileNameBody = StringUtility::getUniqueId('write-gif'); $imResult = $imageProcessor->imageMagickConvert($inputFile, 'gif', '', '', '', '', array(), true); if ($imResult !== null && is_file($imResult[3])) { if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress']) { clearstatcache(); $previousSize = GeneralUtility::formatSize(filesize($imResult[3])); $methodUsed = GraphicalFunctions::gifCompress($imResult[3], ''); clearstatcache(); $compressedSize = GeneralUtility::formatSize(filesize($imResult[3])); /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */ $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\InfoStatus::class); $message->setTitle('Compressed gif'); $message->setMessage('Method used by compress: ' . $methodUsed . LF . ' Previous filesize: ' . $previousSize . '. Current filesize:' . $compressedSize); } else { /** @var \TYPO3\CMS\Install\Status\StatusInterface $message */ $message = $this->objectManager->get(\TYPO3\CMS\Install\Status\InfoStatus::class); $message->setTitle('Gif compression not enabled by [GFX][gif_compress]'); } $testResults['gif']['message'] = $message; $testResults['gif']['title'] = 'Write gif'; $testResults['gif']['outputFile'] = $imResult[3]; $testResults['gif']['referenceFile'] = $this->imageBasePath . 'TestReference/Write-gif.gif'; $testResults['gif']['command'] = $imageProcessor->IM_commands; } else { $testResults['gif']['error'] = $this->imageGenerationFailedMessage(); } // Png $inputFile = $this->imageBasePath . 'TestInput/Test.png'; $imageProcessor->IM_commands = array(); $imageProcessor->imageMagickConvert_forceFileNameBody = StringUtility::getUniqueId('write-png'); $imResult = $imageProcessor->imageMagickConvert($inputFile, 'png', '', '', '', '', array(), true); if ($imResult !== null) { $testResults['png']['title'] = 'Write png'; $testResults['png']['outputFile'] = $imResult[3]; $testResults['png']['referenceFile'] = $this->imageBasePath . 'TestReference/Write-png.png'; $testResults['png']['command'] = $imageProcessor->IM_commands; } else { $testResults['png']['error'] = $this->imageGenerationFailedMessage(); } $this->view->assign('testResults', $testResults); return $this->imageTestDoneMessage(GeneralUtility::milliseconds() - $parseTimeStart); }
/** * Creates the icon file for the function getIcon() * * @param string $iconfile Original unprocessed Icon file, relative path to PATH_typo3 * @param string $mode Mode string, eg. "deleted" or "futuretiming" determining how the icon will look * @param int $user The number of the fe_group record uid if applicable * @param bool $protectSection Flag determines if the protected-section icon should be applied. * @param string $absFile Absolute path to file from which to create the icon. * @param string $iconFileName_stateTagged The filename that this icon should have had, basically [icon base name]_[flags].[extension] - used for part of temporary filename * @return string Filename relative to PATH_typo3 * @access private */ public static function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged) { $iconFileName = GeneralUtility::shortMD5($iconfile . '|' . $mode . '|-' . $user . '|' . $protectSection) . '_' . $iconFileName_stateTagged . '.' . ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png'] ? 'png' : 'gif'); $mainpath = '../typo3temp/Icons/' . $iconFileName; $path = PATH_site . 'typo3temp/Icons/' . $iconFileName; if (file_exists($path)) { // Returns if found in ../typo3temp/Icons/ return $mainpath; } else { // Makes icon: if (file_exists($absFile)) { if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) { // Create image pointer, if possible $im = self::imagecreatefrom($absFile); if ($im < 0) { return $iconfile; } // Converting to gray scale, dimming the icon: if ($mode == 'disabled' or $mode != 'futuretiming' && $mode != 'no_icon_found' && !(!$mode && $user)) { $totalImageColors = ImageColorsTotal($im); for ($c = 0; $c < $totalImageColors; $c++) { $cols = ImageColorsForIndex($im, $c); $newcol = round(($cols['red'] + $cols['green'] + $cols['blue']) / 3); $lighten = $mode == 'disabled' ? 2.5 : 2; $newcol = round(255 - (255 - $newcol) / $lighten); ImageColorSet($im, $c, $newcol, $newcol, $newcol); } } // Applying user icon, if there are access control on the item: if ($user) { if ($user < 100) { // Apply user number only if lower than 100 $black = ImageColorAllocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, $user > 10 ? 9 : 5, 8, $black); $white = ImageColorAllocate($im, 255, 255, 255); imagestring($im, 1, 1, 1, $user, $white); } $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_group.gif'); if ($ol_im < 0) { return $iconfile; } self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im)); } // Applying overlay based on mode: if ($mode) { unset($ol_im); switch ($mode) { case 'deleted': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_deleted.gif'); break; case 'futuretiming': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_timing.gif'); break; case 'timing': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_timing.gif'); break; case 'hiddentiming': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_hidden_timing.gif'); break; case 'no_icon_found': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_no_icon_found.gif'); break; case 'disabled': // is already greyed - nothing more $ol_im = 0; break; case 'hidden': default: $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_hidden.gif'); } if ($ol_im < 0) { return $iconfile; } if ($ol_im) { self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im)); } } // Protect-section icon: if ($protectSection) { $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/overlay_sub5.gif'); if ($ol_im < 0) { return $iconfile; } self::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im)); } // Create the image as file, destroy GD image and return: $targetDirectory = dirname($path); if (!@is_dir($targetDirectory)) { GeneralUtility::mkdir($targetDirectory); } @self::imagemake($im, $path); GraphicalFunctions::gifCompress($path, 'IM'); ImageDestroy($im); return $mainpath; } else { return $iconfile; } } else { return $GLOBALS['BACK_PATH'] . 'typo3/sysext/backend/Resources/Public/Images/Overlay/default.gif'; } } }
/** * Compressing a GIF file if not already LZW compressed. * This function is a workaround for the fact that ImageMagick and/or GD does not compress GIF-files to their minimun size (that is RLE or no compression used) * * The function takes a file-reference, $theFile, and saves it again through GD or ImageMagick in order to compress the file * GIF: * If $type is not set, the compression is done with ImageMagick (provided that $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] is pointing to the path of a lzw-enabled version of 'convert') else with GD (should be RLE-enabled!) * If $type is set to either 'IM' or 'GD' the compression is done with ImageMagick and GD respectively * PNG: * No changes. * * $theFile is expected to be a valid GIF-file! * The function returns a code for the operation. * * @param string $theFile Filepath * @param string $type See description of function * @return string Returns "GD" if GD was used, otherwise "IM" if ImageMagick was used. If nothing done at all, it returns empty string. * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. Use \TYPO3\CMS\Core\Imaging\GraphicalFunctions::gifCompress() instead. */ public static function gif_compress($theFile, $type) { static::logDeprecatedFunction(); $returnCode = GraphicalFunctions::gifCompress($theFile, $type); return $returnCode; }