From 4be10997db5a29e57586193b99d125c60a4331b2 Mon Sep 17 00:00:00 2001 From: twoldanski <66474451+twoldanski@users.noreply.github.com> Date: Mon, 27 May 2024 11:55:15 +0200 Subject: [PATCH] [BUGFIX] Make processing PDF/SVG files optional (#736) --- Classes/Utility/File/ProcessingConfiguration.php | 4 ++++ Classes/Utility/FileUtility.php | 12 +++++++++++- Documentation/Developer/Images.rst | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Classes/Utility/File/ProcessingConfiguration.php b/Classes/Utility/File/ProcessingConfiguration.php index e64a6c84..4d30d5b7 100644 --- a/Classes/Utility/File/ProcessingConfiguration.php +++ b/Classes/Utility/File/ProcessingConfiguration.php @@ -40,6 +40,8 @@ public static function fromOptions(array $options): static (int)($options['linkResult'] ?? 0) > 0, (int)($options['properties.']['flatten'] ?? 0) > 0, ((int)($options['properties.']['byType'] ?? 0)) > 0, + (int)($options['processPdfAsImage'] ?? 0) > 0, + (int)($options['processSvg'] ?? 0) > 0, GeneralUtility::trimExplode(',', $options['properties.']['includeOnly'] ?? '', true), GeneralUtility::trimExplode(',', $options['properties.']['defaultFieldsByType'] ?? '', true), GeneralUtility::trimExplode(',', $options['properties.']['defaultImageFields'] ?? '', true), @@ -66,6 +68,8 @@ private function __construct( public readonly bool $linkResult = false, public readonly bool $flattenProperties = false, public readonly bool $propertiesByType = false, + public readonly bool $processPdfAsImage = false, + public readonly bool $processSvg = false, public readonly array $includeProperties = [], public readonly array $defaultFieldsByType = [], public readonly array $defaultImageFields = [], diff --git a/Classes/Utility/FileUtility.php b/Classes/Utility/FileUtility.php index a8ad5894..c4c4b8a9 100644 --- a/Classes/Utility/FileUtility.php +++ b/Classes/Utility/FileUtility.php @@ -93,7 +93,17 @@ public function process(FileInterface $fileReference, ProcessingConfiguration $p $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileReference->getExtension() )) { - if (!$processingConfiguration->delayProcessing && $fileReference->getMimeType() !== 'image/svg+xml') { + $disableProcessingFor = []; + + if (!$processingConfiguration->processPdfAsImage) { + $disableProcessingFor[] = 'application/pdf'; + } + + if (!$processingConfiguration->processSvg) { + $disableProcessingFor[] = 'image/svg+xml'; + } + + if (!$processingConfiguration->delayProcessing && !in_array($fileReference->getMimeType(), $disableProcessingFor, true)) { $fileReference = $this->processImageFile($fileReference, $processingConfiguration); } $publicUrl = $this->imageService->getImageUri($fileReference, true); diff --git a/Documentation/Developer/Images.rst b/Documentation/Developer/Images.rst index b1128565..2c480a23 100644 --- a/Documentation/Developer/Images.rst +++ b/Documentation/Developer/Images.rst @@ -133,7 +133,12 @@ The rendering configuration can be set via the property `processingConfiguration * `linkResult` (0|1): Allows to define if file object should return only url of defined link or whole LinkResult object * `cacheBusting` (0|1): Allows to enable cacheBusting urls for processed files * `conditionalCropVariant` (0|1): Allows conditionally autogenerate files with defined variants if set (if not all variants are returned) +* `processPdfAsImage` (0|1): Enabled optional processing pdf files as image (default off) +* `processSvg` (0|1): Enabled optional processing svg files (default off) * `properties.byType` (0|1): Allows filter file properties by type (i.e. do not return video properties on images) +* `properties.defaultFieldsByType` (coma separated list of fields): Default fields for when enabled option `properties.byType` +* `properties.defaultImageFields` (coma separated list of fields): Default fields for image type when enabled option `properties.byType` +* `properties.defaultVideoFields` (coma separated list of fields): Default fields for video type when enabled option `properties.byType` * `properties.includeOnly` (string, comma separated): Configure what file properties to return * `properties.flatten` (0|1): Flatten nested properties (dimensions array) to use with `properties.includeOnly` * `returnFlattenObject`: without that flag an array of (multiple) images is rendered. Set this if you're only rendering 1 image and want to reduce nesting.