[BUGFIX] Add imageMagickIdentify fallback to ImageInfo::getImageSizes() 68/38468/2
authorFrans Saris <franssaris@gmail.com>
Wed, 1 Apr 2015 20:32:44 +0000 (22:32 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Sat, 4 Apr 2015 11:05:45 +0000 (13:05 +0200)
ImageInfo::getImageSizes() uses getimagesize() to determine the image dimensions. But for pdf and svg files this fails.

This patch add a fallback to GraphicalFunctions::imageMagickIdentify()
when getimagesize() doesn't give any results.

This patch also changes the Indexer::extractRequiredMetaData() as is
had the same issue. It now used the ImageInfo object.

Resolves: #66268
Releases: master, 6.2
Change-Id: I51d8ee5106b07667139f49a7acdfaabf99501a5b
Reviewed-on: http://review.typo3.org/38468
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Resource/Index/Indexer.php
typo3/sysext/core/Classes/Type/File/ImageInfo.php

index e122a6e..4f622a5 100644 (file)
@@ -16,6 +16,8 @@ namespace TYPO3\CMS\Core\Resource\Index;
 
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Resource\File;
+use TYPO3\CMS\Core\Type\File\ImageInfo;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * The New FAL Indexer
@@ -214,8 +216,11 @@ class Indexer {
                // prevent doing this for remote storages, remote storages must provide the data with extractors
                if ($fileObject->getType() == File::FILETYPE_IMAGE && $this->storage->getDriverType() === 'Local') {
                        $rawFileLocation = $fileObject->getForLocalProcessing(FALSE);
-                       $metaData = array();
-                       list($metaData['width'], $metaData['height']) = getimagesize($rawFileLocation);
+                       $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $rawFileLocation);
+                       $metaData = array(
+                               'width' => $imageInfo->getWidth(),
+                               'height' => $imageInfo->getHeight(),
+                       );
                        $this->getMetaDataRepository()->update($fileObject->getUid(), $metaData);
                        $fileObject->_updateMetaDataProperties($metaData);
                }
index a41c716..c089258 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Type\File;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
+use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -53,8 +55,13 @@ class ImageInfo extends FileInfo {
                if (is_null($this->imageSizes)) {
                        $this->imageSizes = getimagesize($this->getPathname());
 
-                       // In case the image size could not be retrieved, log the incident as a warning.
+                       // Fallback to IM identify
                        if ($this->imageSizes === FALSE) {
+                               $this->imageSizes = $this->getGraphicalFunctions()->imageMagickIdentify($this->getPathname());
+                       }
+
+                       // In case the image size could not be retrieved, log the incident as a warning.
+                       if (empty($this->imageSizes)) {
                                $this->getLogger()->warning('I could not retrieve the image size for file ' . $this->getPathname());
                                $this->imageSizes = array(0, 0);
                        }
@@ -66,10 +73,22 @@ class ImageInfo extends FileInfo {
         * @return \TYPO3\CMS\Core\Log\Logger
         */
        protected function getLogger(){
-               /** @var $loggerManager \TYPO3\CMS\Core\Log\LogManager */
-               $loggerManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class);
+               /** @var $loggerManager LogManager */
+               $loggerManager = GeneralUtility::makeInstance(LogManager::class);
 
                return $loggerManager->getLogger(get_class($this));
        }
 
+       /**
+        * @return GraphicalFunctions
+        */
+       protected function getGraphicalFunctions() {
+               static $graphicalFunctions = NULL;
+
+               if ($graphicalFunctions === NULL) {
+                       $graphicalFunctions = GeneralUtility::makeInstance(GraphicalFunctions::class);
+               }
+
+               return $graphicalFunctions;
+       }
 }