Commit 2fb7be7b authored by Markus Klein's avatar Markus Klein Committed by Frans Saris
Browse files

[TASK] Use ImageInfo class instead of direct PHP GD call

This ensures maximum compatibility with all available graphics
commands.

Resolves: #78600
Releases: master, 8.7
Change-Id: Id7a95fbdf7782fef59e18de3dc4522d7c68b690a
Reviewed-on: https://review.typo3.org/56622

Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarFlorian Weiss <typo3org@leblanc.at>
Tested-by: default avatarFlorian Weiss <typo3org@leblanc.at>
Reviewed-by: default avatarMathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: default avatarMathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Frans Saris's avatarFrans Saris <franssaris@gmail.com>
Tested-by: Frans Saris's avatarFrans Saris <franssaris@gmail.com>
parent 34067326
......@@ -21,7 +21,6 @@ use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
/**
* This is a static, internal and intermediate helper class for various
......@@ -124,21 +123,15 @@ class FormEngineUtility
$icon = (string)$icon;
$absoluteFilePath = GeneralUtility::getFileAbsFileName($icon);
if (!empty($absoluteFilePath) && is_file($absoluteFilePath)) {
$iconInfo = StringUtility::endsWith($absoluteFilePath, '.svg')
? true
: getimagesize($absoluteFilePath);
if ($iconInfo !== false) {
return '<img'
. ' src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($absoluteFilePath)) . '"'
. ' alt="' . htmlspecialchars($alt) . '" '
. ($title ? 'title="' . htmlspecialchars($title) . '"' : '')
return '<img'
. ' src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($absoluteFilePath)) . '"'
. ' alt="' . htmlspecialchars($alt) . '" '
. ($title ? 'title="' . htmlspecialchars($title) . '"' : '')
. ' />';
}
}
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
return '<span alt="' . htmlspecialchars($alt) . '" title="' . htmlspecialchars($title) . '">'
return '<span title="' . htmlspecialchars($title) . '">'
. $iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render()
. '</span>';
}
......
......@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Resource;
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Service\TypoLinkCodecService;
......@@ -393,7 +394,11 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
];
if (!$imageInfo[0] || !$imageInfo[1]) {
$filePath = $originalImageFile->getForLocalProcessing(false);
$imageInfo = @getimagesize($filePath);
$imageInfoObject = GeneralUtility::makeInstance(ImageInfo::class, $filePath);
$imageInfo = [
$imageInfoObject->getWidth(),
$imageInfoObject->getHeight()
];
}
$attribArray = $this->applyPlainImageModeSettings($imageInfo, $attribArray);
}
......@@ -448,7 +453,11 @@ class RteHtmlParser extends HtmlParser implements LoggerAwareInterface
if ($this->procOptions['plainImageMode']) {
// If "plain image mode" has been configured
// Find the original dimensions of the image
$imageInfo = @getimagesize($filepath);
$imageInfoObject = GeneralUtility::makeInstance(ImageInfo::class, $filepath);
$imageInfo = [
$imageInfoObject->getWidth(),
$imageInfoObject->getHeight()
];
$attribArray = $this->applyPlainImageModeSettings($imageInfo, $attribArray);
}
// Let's try to find a file uid for this image
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Core\Imaging;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
......@@ -2169,22 +2170,24 @@ class GraphicalFunctions
*/
public function getImageDimensions($imageFile)
{
$returnArr = null;
preg_match('/([^\\.]*)$/', $imageFile, $reg);
if (file_exists($imageFile) && in_array(strtolower($reg[0]), $this->imageFileExt, true)) {
if ($returnArr = $this->getCachedImageDimensions($imageFile)) {
return $returnArr;
}
if ($temp = @getimagesize($imageFile)) {
$returnArr = [$temp[0], $temp[1], strtolower($reg[0]), $imageFile];
} else {
$returnArr = $this->imageMagickIdentify($imageFile);
}
if ($returnArr) {
$this->cacheImageDimensions($returnArr);
return $returnArr;
$returnArr = $this->getCachedImageDimensions($imageFile);
if (!$returnArr) {
$imageInfoObject = GeneralUtility::makeInstance(ImageInfo::class, $imageFile);
if ($imageInfoObject->getWidth()) {
$returnArr = [
$imageInfoObject->getWidth(),
$imageInfoObject->getHeight(),
strtolower($reg[0]),
$imageFile
];
$this->cacheImageDimensions($returnArr);
}
}
}
return null;
return $returnArr;
}
/**
......@@ -2780,10 +2783,10 @@ class GraphicalFunctions
break;
}
// If non of the above:
$i = @getimagesize($sourceImg);
$im = imagecreatetruecolor($i[0], $i[1]);
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $sourceImg);
$im = imagecreatetruecolor($imageInfo->getWidth(), $imageInfo->getHeight());
$Bcolor = imagecolorallocate($im, 128, 128, 128);
imagefilledrectangle($im, 0, 0, $i[0], $i[1], $Bcolor);
imagefilledrectangle($im, 0, 0, $imageInfo->getWidth(), $imageInfo->getHeight(), $Bcolor);
return $im;
}
......
......@@ -23,6 +23,7 @@ use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\ProcessedFileRepository;
use TYPO3\CMS\Core\Resource\Processing\LocalImageProcessor;
use TYPO3\CMS\Core\Resource\Service\FileProcessingService;
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\CommandUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Imaging\GifBuilder;
......@@ -92,11 +93,11 @@ class PreviewProcessing
GeneralUtility::unlink_tempfile($temporaryFileName);
if (is_file($temporaryFileNameForResizedThumb)) {
$processedFile->setName($this->getTargetFileName($processedFile));
list($width, $height) = getimagesize($temporaryFileNameForResizedThumb);
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $temporaryFileNameForResizedThumb);
$processedFile->updateProperties(
[
'width' => $width,
'height' => $height,
'width' => $imageInfo->getWidth(),
'height' => $imageInfo->getHeight(),
'size' => filesize($temporaryFileNameForResizedThumb),
'checksum' => $processedFile->getTask()->getConfigurationChecksum()
]
......
......@@ -58,8 +58,10 @@ class ImageInfo extends FileInfo implements LoggerAwareInterface
protected function getImageSizes()
{
if ($this->imageSizes === null) {
$this->imageSizes = getimagesize($this->getPathname());
$this->imageSizes = false;
if (function_exists('getimagesize')) {
$this->imageSizes = @getimagesize($this->getPathname());
}
// Try SVG first as SVG size detection with IM/GM leads to an error output
if ($this->imageSizes === false && $this->getMimeType() === 'image/svg+xml') {
$this->imageSizes = $this->extractSvgImageSizes();
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Documentation\Domain\Repository;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
......@@ -202,7 +203,6 @@ class TableManualRepository
{
$this->getLanguageService()->loadSingleTableDescription($key);
// Define the label for the key
$keyName = $key;
if (!empty($GLOBALS['TCA_DESCR'][$key]['columns']['']['alttitle'])) {
// If there's an alternative title, use it
$keyName = $GLOBALS['TCA_DESCR'][$key]['columns']['']['alttitle'];
......@@ -361,8 +361,8 @@ class TableManualRepository
$absImagePath = GeneralUtility::getFileAbsFileName($image);
if ($absImagePath && @is_file($absImagePath)) {
$imgFile = PathUtility::stripPathSitePrefix($absImagePath);
$imgInfo = @getimagesize($absImagePath);
if (is_array($imgInfo)) {
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $absImagePath);
if ($imageInfo->getWidth()) {
$imageData[] = [
'image' => $imgFile,
'description' => $descriptions
......
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
*/
use TYPO3\CMS\Core\Package\PackageInterface;
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
......@@ -268,14 +269,10 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface
public function enrichExtensionsWithIconInformation(array $extensions)
{
foreach ($extensions as &$properties) {
$iInfo = @getimagesize(PATH_site . $properties['siteRelPath'] . $properties['ext_icon']);
if ($iInfo !== false) {
$properties['ext_icon_width'] = $iInfo[0];
$properties['ext_icon_height'] = $iInfo[1];
} else {
$properties['ext_icon_width'] = 0;
$properties['ext_icon_height'] = 0;
}
$extIconPath = PATH_site . $properties['siteRelPath'] . $properties['ext_icon'];
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $extIconPath);
$properties['ext_icon_width'] = $imageInfo->getWidth();
$properties['ext_icon_height'] = $imageInfo->getHeight();
}
unset($properties);
return $extensions;
......
......@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Frontend\ContentObject;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
......@@ -36,9 +37,12 @@ class FileContentObject extends AbstractContentObject
$fileInfo = GeneralUtility::split_fileref($file);
$extension = $fileInfo['fileext'];
if ($extension === 'jpg' || $extension === 'jpeg' || $extension === 'gif' || $extension === 'png') {
$imgInfo = @getimagesize($file);
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $file);
$altParameters = trim($this->cObj->getAltParam($conf, false));
$theValue = '<img src="' . htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix . $file) . '" width="' . (int)$imgInfo[0] . '" height="' . (int)$imgInfo[1] . '"' . $this->cObj->getBorderAttr(' border="0"') . ' ' . $altParameters . ' />';
$theValue = '<img src="'
. htmlspecialchars($this->getTypoScriptFrontendController()->absRefPrefix . $file)
. '" width="' . (int)$imageInfo->getWidth() . '" height="' . (int)$imageInfo->getHeight()
. '"' . $this->cObj->getBorderAttr(' border="0"') . ' ' . $altParameters . ' />';
} elseif (filesize($file) < 1024 * 1024) {
$theValue = file_get_contents($file);
}
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Frontend\ContentObject\Menu;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
......@@ -242,9 +243,9 @@ class GraphicalMenuContentObject extends AbstractMenuContentObject
// Generation of image file:
// File exists
if (file_exists($gifFileName)) {
$info = @getimagesize($gifFileName);
$this->result[$resKey][$key]['output_w'] = (int)$info[0];
$this->result[$resKey][$key]['output_h'] = (int)$info[1];
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $gifFileName);
$this->result[$resKey][$key]['output_w'] = (int)$imageInfo->getWidth();
$this->result[$resKey][$key]['output_h'] = (int)$imageInfo->getHeight();
$this->result[$resKey][$key]['output_file'] = $gifFileName;
} elseif ($isGD) {
// file is generated
......
......@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Frontend\ContentObject\Menu;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
......@@ -199,9 +200,9 @@ class ImageMenuContentObject extends AbstractMenuContentObject
$imgMap = $cache->get($imgHash);
// File exists
if ($imgMap && file_exists($gifFileName)) {
$info = @getimagesize($gifFileName);
$w = $info[0];
$h = $info[1];
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $gifFileName);
$w = $imageInfo->getWidth();
$h = $imageInfo->getHeight();
} else {
// file is generated
$gifCreator->make();
......
......@@ -20,6 +20,7 @@ use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
use TYPO3\CMS\Core\Html\HtmlParser;
use TYPO3\CMS\Core\Type\File\ImageInfo;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\IpAnonymizationUtility;
......@@ -695,9 +696,14 @@ class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControlle
if ($icon) {
$fullPath = GeneralUtility::getFileAbsFileName($icon);
if ($fullPath) {
$info = @getimagesize($fullPath);
$iconPath = \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($fullPath);
$this->iconFileNameCache[$imageType] = is_array($info) ? '<img src="' . $iconPath . '" ' . $info[3] . ' title="' . htmlspecialchars($alt) . '" alt="" />' : '';
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $fullPath);
$iconPath = PathUtility::stripPathSitePrefix($fullPath);
$this->iconFileNameCache[$imageType] = $imageInfo->getWidth()
? '<img src="' . $iconPath
. '" width="' . $imageInfo->getWidth()
. '" height="' . $imageInfo->getHeight()
. '" title="' . htmlspecialchars($alt) . '" alt="" />'
: '';
}
}
}
......
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