Commit ef529087 authored by Benni Mack's avatar Benni Mack Committed by Andreas Fernandez
Browse files

[TASK] Deprecate GraphicalFunctions->init method

The init method of GraphicalFunctions/Gifbuilder was used instead of
a constructor to set up various internal properties, and is now
shifted into a new constructor, making the extra call to init() superfluous.

Resolves: #85978
Releases: master
Change-Id: I71ee3bc8045f48b1636e46681dddd742ba1f56c4
Reviewed-on: https://review.typo3.org/58023

Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 19010709
......@@ -135,9 +135,10 @@ class GraphicalFunctions
];
/**
* Whether ImageMagick/GraphicsMagick is enabled or not
* @var bool
*/
protected $NO_IMAGE_MAGICK = false;
protected $processorEnabled;
/**
* @var bool
......@@ -298,10 +299,10 @@ class GraphicalFunctions
protected $im;
/**
* Init function. Must always call this when using the class.
* This function will read the configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX'] can set some values in internal variables.
* Reads configuration information from $GLOBALS['TYPO3_CONF_VARS']['GFX']
* and sets some values in internal variables.
*/
public function init()
public function __construct()
{
$gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
if (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) {
......@@ -319,9 +320,54 @@ class GraphicalFunctions
$this->colorspace = $gfxConf['processor_colorspace'];
}
if (!$gfxConf['processor_enabled']) {
$this->NO_IMAGE_MAGICK = true;
$this->processorEnabled = (bool)$gfxConf['processor_enabled'];
// Setting default JPG parameters:
$this->jpegQuality = MathUtility::forceIntegerInRange($gfxConf['jpg_quality'], 10, 100, 85);
$this->addFrameSelection = (bool)$gfxConf['processor_allowFrameSelection'];
if ($gfxConf['gdlib_png']) {
$this->gifExtension = 'png';
}
$this->imageFileExt = GeneralUtility::trimExplode(',', $gfxConf['imagefile_ext']);
// Boolean. This is necessary if using ImageMagick 5+.
// Effects in Imagemagick 5+ tends to render very slowly!!
// - therefore must be disabled in order not to perform sharpen, blurring and such.
$this->cmds['jpg'] = $this->cmds['jpeg'] = '-colorspace ' . $this->colorspace . ' -quality ' . $this->jpegQuality;
// ... but if 'processor_effects' is set, enable effects
if ($gfxConf['processor_effects']) {
$this->processorEffectsEnabled = true;
$this->cmds['jpg'] .= $this->v5_sharpen(10);
$this->cmds['jpeg'] .= $this->v5_sharpen(10);
}
// Secures that images are not scaled up.
$this->mayScaleUp = (bool)$gfxConf['processor_allowUpscaling'];
$this->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
}
/**
* @deprecated will be removed in TYPO3 v10.0. As the constructor does everything directly
*/
public function init()
{
trigger_error('GraphicalFunctions->init() will be removed in TYPO3 v10.0. Simply remove the call to the method, since this is now evaluted in the constructor.', E_USER_DEPRECATED);
$gfxConf = $GLOBALS['TYPO3_CONF_VARS']['GFX'];
if (function_exists('imagecreatefromjpeg') && function_exists('imagejpeg')) {
$this->gdlibExtensions[] = 'jpg';
$this->gdlibExtensions[] = 'jpeg';
}
if (function_exists('imagecreatefrompng') && function_exists('imagepng')) {
$this->gdlibExtensions[] = 'png';
}
if (function_exists('imagecreatefromgif') && function_exists('imagegif')) {
$this->gdlibExtensions[] = 'gif';
}
if ($gfxConf['processor_colorspace'] && in_array($gfxConf['processor_colorspace'], $this->allowedColorSpaceNames, true)) {
$this->colorspace = $gfxConf['processor_colorspace'];
}
$this->processorEnabled = (bool)$gfxConf['processor_enabled'];
// Setting default JPG parameters:
$this->jpegQuality = MathUtility::forceIntegerInRange($gfxConf['jpg_quality'], 10, 100, 85);
$this->addFrameSelection = (bool)$gfxConf['processor_allowFrameSelection'];
......@@ -2053,7 +2099,7 @@ class GraphicalFunctions
*/
public function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $params = '', $frame = '', $options = [], $mustCreate = false)
{
if ($this->NO_IMAGE_MAGICK) {
if (!$this->processorEnabled) {
// Returning file info right away
return $this->getImageDimensions($imagefile);
}
......@@ -2406,7 +2452,7 @@ class GraphicalFunctions
*/
public function imageMagickIdentify($imagefile)
{
if ($this->NO_IMAGE_MAGICK) {
if (!$this->processorEnabled) {
return null;
}
......@@ -2449,7 +2495,7 @@ class GraphicalFunctions
*/
public function imageMagickExec($input, $output, $params, $frame = 0)
{
if ($this->NO_IMAGE_MAGICK) {
if (!$this->processorEnabled) {
return '';
}
// If addFrameSelection is set in the Install Tool, a frame number is added to
......@@ -2475,7 +2521,7 @@ class GraphicalFunctions
*/
public function combineExec($input, $overlay, $mask, $output)
{
if ($this->NO_IMAGE_MAGICK) {
if (!$this->processorEnabled) {
return '';
}
$theMask = $this->randomName() . '.' . $this->gifExtension;
......
......@@ -165,9 +165,7 @@ class PreviewProcessing
protected function cropScaleImage($originalFileName, $temporaryFileName, $configuration)
{
if (file_exists($originalFileName)) {
/** @var $gifBuilder GifBuilder */
$gifBuilder = GeneralUtility::makeInstance(GifBuilder::class);
$gifBuilder->init();
$options = $this->getConfigurationForImageCropScaleMask($configuration, $gifBuilder);
$info = $gifBuilder->getImageDimensions($originalFileName);
......@@ -245,10 +243,8 @@ class PreviewProcessing
/**
* @return GraphicalFunctions
*/
protected function getGraphicalFunctionsObject()
protected function getGraphicalFunctionsObject(): GraphicalFunctions
{
$graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class);
$graphicalFunctionsObject->init();
return $graphicalFunctionsObject;
return GeneralUtility::makeInstance(GraphicalFunctions::class);
}
}
......@@ -64,9 +64,7 @@ class LocalCropScaleMaskHelper
$sourceFile = $task->getSourceFile();
$originalFileName = $sourceFile->getForLocalProcessing(false);
/** @var $gifBuilder GifBuilder */
$gifBuilder = GeneralUtility::makeInstance(GifBuilder::class);
$gifBuilder->init();
$configuration = $targetFile->getProcessingConfiguration();
$configuration['additionalParameters'] = $this->modifyImageMagickStripProfileParameters($configuration['additionalParameters'], $configuration);
......
......@@ -140,10 +140,8 @@ class LocalImageProcessor implements ProcessorInterface
/**
* @return GraphicalFunctions
*/
protected function getGraphicalFunctionsObject()
protected function getGraphicalFunctionsObject(): GraphicalFunctions
{
$graphicalFunctionsObject = GeneralUtility::makeInstance(GraphicalFunctions::class);
$graphicalFunctionsObject->init();
return $graphicalFunctionsObject;
return GeneralUtility::makeInstance(GraphicalFunctions::class);
}
}
......@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Frontend\Imaging\GifBuilder;
/**
* Helper for creating local image previews using TYPO3s image processing classes.
......@@ -123,7 +124,6 @@ class LocalPreviewHelper
) {
// Create a default image
$graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
$graphicalFunctions->init();
$graphicalFunctions->getTemporaryImageWithText(
$targetFilePath,
'Not imagefile!',
......@@ -137,9 +137,7 @@ class LocalPreviewHelper
$originalFileName = $file->getForLocalProcessing(false);
if ($file->getExtension() === 'svg') {
/** @var $gifBuilder \TYPO3\CMS\Frontend\Imaging\GifBuilder */
$gifBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Imaging\GifBuilder::class);
$gifBuilder->init();
$gifBuilder = GeneralUtility::makeInstance(GifBuilder::class);
$info = $gifBuilder->getImageDimensions($originalFileName);
$newInfo = $gifBuilder->getImageScale($info, $configuration['width'], $configuration['height'], []);
$result = [
......@@ -159,7 +157,6 @@ class LocalPreviewHelper
if (!file_exists($targetFilePath)) {
// Create an error gif
$graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
$graphicalFunctions->init();
$graphicalFunctions->getTemporaryImageWithText(
$targetFilePath,
'No thumb',
......
......@@ -95,7 +95,6 @@ class ImageInfo extends FileInfo implements LoggerAwareInterface
// Fallback to IM/GM identify
if ($this->imageSizes === false) {
$graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
$graphicalFunctions->init();
$this->imageSizes = $graphicalFunctions->imageMagickIdentify($this->getPathname());
}
......
.. include:: ../../Includes.txt
=================================================================
Deprecation: #85978 - Deprecate GraphicalFunctions->init() method
=================================================================
See :issue:`85978`
Description
===========
The init method of :php:`GraphicalFunctions/Gifbuilder` was used instead of a constructor to set up various internal properties, and is now shifted into a new constructor, making the extra call to init() superfluous.
Impact
======
Calling the method directly will trigger a deprecation warning.
Affected Installations
======================
Any TYPO3 installation with extensions directly calling this method.
Migration
=========
No migration needed, the constructor of :php:`GraphicalFunctions/Gifbuilder` takes care of the initalization of all settings.
.. index:: PHP-API, FullyScanned, ext:core
\ No newline at end of file
......@@ -14,24 +14,10 @@ namespace TYPO3\CMS\Core\Tests\Unit\Imaging;
* The TYPO3 project - inspiring people to share!
*/
/**
* Testcase for \TYPO3\CMS\Core\Imaging\GraphicalFunctions
*/
use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
class GraphicalFunctionsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
{
/**
* @var \TYPO3\CMS\Core\Imaging\GraphicalFunctions
*/
protected $subject;
/**
* Set up
*/
protected function setUp()
{
$this->subject = new \TYPO3\CMS\Core\Imaging\GraphicalFunctions();
}
/**
* Dataprovider for getScaleForImage
*
......@@ -104,7 +90,8 @@ class GraphicalFunctionsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestC
*/
public function getScaleForImage($info, $width, $height, $options, $expected)
{
$result = $this->subject->getImageScale($info, $width, $height, $options);
$this->resetSingletonInstances = true;
$result = (new GraphicalFunctions())->getImageScale($info, $width, $height, $options);
$this->assertEquals($result, $expected);
}
}
......@@ -53,7 +53,6 @@ class ImageInfoTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
];
$graphicalFunctionsProphecy = $this->prophesize(GraphicalFunctions::class);
$graphicalFunctionsProphecy->init()->shouldBeCalled();
$graphicalFunctionsProphecy->imageMagickIdentify($root->url() . '/' . $testFile)->willReturn(null);
GeneralUtility::addInstance(GraphicalFunctions::class, $graphicalFunctionsProphecy->reveal());
......
......@@ -4618,9 +4618,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
}
$imageResource = null;
if ($file === 'GIFBUILDER') {
/** @var GifBuilder $gifCreator */
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$theImage = '';
if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
$gifCreator->start($fileArray, $this->data);
......@@ -4725,9 +4723,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
if (!isset($imageResource)) {
try {
$theImage = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize((string)$file);
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$info = $gifCreator->imageMagickConvert($theImage, 'WEB');
$info = GeneralUtility::makeInstance(GifBuilder::class)->imageMagickConvert($theImage, 'WEB');
$info['origFile'] = $theImage;
// This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder, ln 100ff in order for the setup-array to create a unique filename hash.
$info['origFile_mtime'] = @filemtime($theImage);
......
......@@ -153,7 +153,6 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
if ($isGD) {
// Pre-working the item
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$gifCreator->start($val, $this->menuArr[$key]);
// If useLargestItemH/W is specified
if (!empty($totalWH) && ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'])) {
......@@ -167,7 +166,6 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
// Regenerate the new values...
$val['XY'] = implode(',', $tempXY);
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$gifCreator->start($val, $this->menuArr[$key]);
}
// If distributeH/W is specified
......@@ -188,7 +186,6 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
// Regenerate the new values...
$val['XY'] = implode(',', $tempXY);
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$gifCreator->start($val, $this->menuArr[$key]);
}
// If max dimensions are specified
......@@ -205,7 +202,6 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
if ($maxFlag) {
$val['XY'] = implode(',', $tempXY);
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$gifCreator->start($val, $this->menuArr[$key]);
}
}
......@@ -323,7 +319,6 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
}
$c++;
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$gifCreator->start($val, $this->menuArr[$key]);
if ($maxDim) {
$tempXY = explode(',', $val['XY']);
......@@ -338,7 +333,6 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
if ($maxFlag) {
$val['XY'] = implode(',', $tempXY);
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$gifCreator->start($val, $this->menuArr[$key]);
}
}
......
......@@ -61,7 +61,6 @@ class ImageMenuContentObject extends AbstractMenuContentObject
}
if (is_array($this->mconf['main.'])) {
$gifCreator = GeneralUtility::makeInstance(GifBuilder::class);
$gifCreator->init();
$itemsConf = $conf;
$conf = $this->mconf['main.'];
if (is_array($conf)) {
......
......@@ -62,7 +62,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
if (empty($page)) {
throw new UnableToLinkException('Page id "' . $linkDetails['typoLinkParameter'] . '" was not found, so "' . $linkText . '" was not linked.', 1490987336, null, $linkText);
}
$language = $page[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
$language = (int)$page[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
if ($language === 0 && GeneralUtility::hideIfDefaultLanguage($page['l18n_cfg'])) {
throw new UnableToLinkException('Default language of page "' . $linkDetails['typoLinkParameter'] . '" is hidden, so "' . $linkText . '" was not linked.', 1529527301, null, $linkText);
}
......
......@@ -826,7 +826,6 @@ class EnvironmentController extends AbstractController
protected function initializeImageProcessor(): GraphicalFunctions
{
$imageProcessor = GeneralUtility::makeInstance(GraphicalFunctions::class);
$imageProcessor->init();
$imageProcessor->dontCheckForExistingTempFile = true;
$imageProcessor->filenamePrefix = 'installTool-';
$imageProcessor->dontCompress = true;
......
......@@ -3005,4 +3005,18 @@ return [
'Deprecation-85960-CompareUidentDeprecated.rst'
],
],
'TYPO3\CMS\Core\Imaging\GraphicalFunctions->init' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-85978-DeprecateGraphicalFunctions-initMethod.rst'
],
],
'TYPO3\CMS\Frontend\Imaging\GifBuilder->init' => [
'numberOfMandatoryArguments' => 0,
'maximumNumberOfArguments' => 0,
'restFiles' => [
'Deprecation-85978-DeprecateGraphicalFunctions-initMethod.rst'
],
],
];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment