Skip to content

Commit

Permalink
Implement missing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pegro committed Sep 10, 2018
1 parent 4db1b55 commit 46fdf96
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
33 changes: 23 additions & 10 deletions Classes/Xclass/GifBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,8 @@ public static function gifCompress($theFile, $type)
$temporaryName = dirname($theFile) . '/' . md5(uniqid('', true)) . '.gif';
// Rename could fail, if a simultaneous thread is currently working on the same thing
if (@rename($theFile, $temporaryName)) {
/*
$cmd = CommandUtility::imageMagickCommand('convert', '"' . $temporaryName . '" "' . $theFile . '"', $gfxConf['processor_path_lzw']);
CommandUtility::exec($cmd);
*/
$graphicalFunctions = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\GraphicalFunctions::class);
$graphicalFunctions->imageMagickExec($temporaryName, $theFile, '');
unlink($temporaryName);
}
$returnCode = 'IM';
Expand Down Expand Up @@ -243,12 +241,10 @@ public static function readPngGif($theFile, $output_png = false)
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);
*/

$graphicalFunctions = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\GraphicalFunctions::class);
$graphicalFunctions->imageMagickExec($theFile, $newFile, '');

if (@is_file($newFile)) {
GeneralUtility::fixPermissions($newFile);
return $newFile;
Expand All @@ -272,4 +268,21 @@ public function IMreduceColors($file, $cols) {
return $this->imagick->IMreduceColors($file, $cols);
}

/**
* Create thumbnail of given file and size.
*
* @param $fileIn string filename source
* @param $fileOut string filename target
* @param $w integer width
* @param $h integer height
* @return bool
*/
public function imagickThumbnailImage($fileIn, $fileOut, $w, $h) {
if ($this->NO_IMAGICK) {
return false;
}

return $this->imagick->imagickThumbnailImage($fileIn, $fileOut, $w, $h);
}

}
26 changes: 10 additions & 16 deletions Classes/Xclass/GraphicalFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function init() {
*/
public function getIMversion($returnString = TRUE) {
return $this->imagick->getIMversion($returnString);
}
}

/**
* Executes a ImageMagick "convert" on two filenames, $input and $output using $params before them.
Expand Down Expand Up @@ -101,7 +101,7 @@ public function imageMagickExec($input, $output, $params, $frame = 0) {
*
* @param string $imagefile The relative (to PATH_site) image filepath
* @return array
*/
*/
public function imageMagickIdentify($imagefile) {

if (TYPO3_DLOG)
Expand Down Expand Up @@ -138,8 +138,6 @@ public function combineExec($input, $overlay, $mask, $output, $handleNegation =
}

/**
* TODO convert to imagick
*
* 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)
*
Expand Down Expand Up @@ -172,10 +170,9 @@ public static function gifCompress($theFile, $type)
$temporaryName = dirname($theFile) . '/' . md5(uniqid('', true)) . '.gif';
// Rename could fail, if a simultaneous thread is currently working on the same thing
if (@rename($theFile, $temporaryName)) {
/*
$cmd = CommandUtility::imageMagickCommand('convert', '"' . $temporaryName . '" "' . $theFile . '"', $gfxConf['processor_path_lzw']);
CommandUtility::exec($cmd);
*/
$graphicalFunctions = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\GraphicalFunctions::class);
$graphicalFunctions->init();
$graphicalFunctions->imageMagickExec($temporaryName, $theFile, '');
unlink($temporaryName);
}
$returnCode = 'IM';
Expand All @@ -198,8 +195,6 @@ public static function gifCompress($theFile, $type)
}

/**
* TODO convert to imagick
*
* 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.
*
Expand All @@ -225,12 +220,11 @@ public static function readPngGif($theFile, $output_png = false)
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);
*/

$graphicalFunctions = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\GraphicalFunctions::class);
$graphicalFunctions->init();
$graphicalFunctions->imageMagickExec($theFile, $newFile, '');

if (@is_file($newFile)) {
GeneralUtility::fixPermissions($newFile);
return $newFile;
Expand Down
17 changes: 4 additions & 13 deletions Classes/Xclass/PreviewProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class PreviewProcessing extends \TYPO3\CMS\Core\Resource\OnlineMedia\Processing\PreviewProcessing {

/**
* TODO convert to imagick
* @since Typo3 7.5.0
*
* @param string $originalFileName
* @param string $temporaryFileName
Expand All @@ -52,18 +52,9 @@ protected function resizeImage($originalFileName, $temporaryFileName, $configura
}

if (file_exists($originalFileName)) {
$arguments = \TYPO3\CMS\Core\Utility\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);
*/
$parameters = '-sample ' . $configuration['width'] . 'x' . $configuration['height'];
$graphicalFunctions = $this->getGraphicalFunctionsObject();
$graphicalFunctions->imageMagickExec($originalFileName, $temporaryFileName, $parameters);
}

if (!file_exists($temporaryFileName)) {
Expand Down

0 comments on commit 46fdf96

Please sign in to comment.