From d4549453634b1c42445e5217099ca95518dff5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wolda=C5=84ski?= Date: Mon, 30 Sep 2024 13:57:23 +0200 Subject: [PATCH] [BUGFIX] Add option to process SVG files Resolves: #782 --- Classes/DataProcessing/FilesProcessor.php | 4 ++++ Classes/DataProcessing/GalleryProcessor.php | 4 ++++ Classes/Utility/FileUtility.php | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Classes/DataProcessing/FilesProcessor.php b/Classes/DataProcessing/FilesProcessor.php index 16e6559d..5e577bbc 100644 --- a/Classes/DataProcessing/FilesProcessor.php +++ b/Classes/DataProcessing/FilesProcessor.php @@ -176,6 +176,8 @@ protected function processFiles(array $properties = []): ?array $data = []; $cropVariant = $this->processorConfiguration['processingConfiguration.']['cropVariant'] ?? 'default'; + $this->getFileUtility()->setAllowSvgProcessing((int)($this->processorConfiguration['processingConfiguration.']['processSvg'] ?? 0) === 1); + foreach ($this->fileObjects as $key => $fileObject) { if (isset($this->processorConfiguration['processingConfiguration.']['autogenerate.'])) { $file = $this->getFileUtility()->processFile( @@ -246,6 +248,8 @@ protected function processFiles(array $properties = []): ?array } } + $this->getFileUtility()->setAllowSvgProcessing(false); + if (isset($this->processorConfiguration['processingConfiguration.']['returnFlattenObject']) && (int)$this->processorConfiguration['processingConfiguration.']['returnFlattenObject'] === 1) { return $data[0] ?? null; diff --git a/Classes/DataProcessing/GalleryProcessor.php b/Classes/DataProcessing/GalleryProcessor.php index a06b76cb..fc9e3849 100644 --- a/Classes/DataProcessing/GalleryProcessor.php +++ b/Classes/DataProcessing/GalleryProcessor.php @@ -178,6 +178,8 @@ private function getCroppedDimensionalPropertyFromProcessedFile(array $processed */ protected function prepareGalleryData() { + $this->getFileUtility()->setAllowSvgProcessing((int)($this->processorConfiguration['processingConfiguration.']['processSvg'] ?? 0) === 1); + for ($row = 1; $row <= $this->galleryData['count']['rows']; $row++) { for ($column = 1; $column <= $this->galleryData['count']['columns']; $column++) { $fileKey = (($row - 1) * $this->galleryData['count']['columns']) + $column - 1; @@ -218,6 +220,8 @@ protected function prepareGalleryData() } } + $this->getFileUtility()->setAllowSvgProcessing(false); + $this->galleryData['columnSpacing'] = $this->columnSpacing; $this->galleryData['border']['enabled'] = $this->borderEnabled; $this->galleryData['border']['width'] = $this->borderWidth; diff --git a/Classes/Utility/FileUtility.php b/Classes/Utility/FileUtility.php index 66bdc3ca..23e80d14 100644 --- a/Classes/Utility/FileUtility.php +++ b/Classes/Utility/FileUtility.php @@ -43,6 +43,7 @@ class FileUtility */ protected array $errors = []; protected Features $features; + protected bool $allowSvgProcessing = false; public function __construct( ?ContentObjectRenderer $contentObjectRenderer = null, @@ -61,6 +62,11 @@ public function __construct( $this->features = $features ?? GeneralUtility::makeInstance(Features::class); } + public function setAllowSvgProcessing(bool $allowSvgProcessing): void + { + $this->allowSvgProcessing = $allowSvgProcessing; + } + /** * @param array $dimensions * @return array @@ -94,7 +100,7 @@ public function processFile( ]; if ($fileRenderer === null && $fileReference->getType() === AbstractFile::FILETYPE_IMAGE) { - if (!$delayProcessing && $fileReference->getMimeType() !== 'image/svg+xml') { + if (!$delayProcessing && ($this->allowSvgProcessing || $fileReference->getMimeType() !== 'image/svg+xml')) { $fileReference = $this->processImageFile($fileReference, $dimensions, $cropVariant); } $publicUrl = $this->imageService->getImageUri($fileReference, true);