[BUGFIX] Try SVG first when detecting image size 45/56545/2
authorAnja <aleichsenring@ab-softlab.de>
Tue, 3 Apr 2018 14:56:50 +0000 (16:56 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Wed, 4 Apr 2018 13:08:55 +0000 (15:08 +0200)
By processing SVG files first and falling back to IM/GM identify, output
of a 'invalid image content' error for SVG files is avoided.

Change-Id: I44a7d822b100bdc83f7afa8aa544b6f3eff194d0
Resolves: #84586
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/56545
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/Type/File/ImageInfo.php

index ab22a59..77322f5 100644 (file)
@@ -57,16 +57,15 @@ class ImageInfo extends FileInfo
         if (is_null($this->imageSizes)) {
             $this->imageSizes = getimagesize($this->getPathname());
 
-            // Fallback to IM identify
+            // 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();
+            }
+            // Fallback to IM/GM identify
             if ($this->imageSizes === false) {
                 $this->imageSizes = $this->getGraphicalFunctions()->imageMagickIdentify($this->getPathname());
             }
 
-            // Extra fallback for SVG
-            if (empty($this->imageSizes) && $this->getMimeType() === 'image/svg+xml') {
-                $this->imageSizes = $this->extractSvgImageSizes();
-            }
-
             // 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());