Skip to content

Commit

Permalink
[BUGFIX] Make processing PDF/SVG files optional (#736)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoldanski authored May 27, 2024
1 parent 5c76ae3 commit 4be1099
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Classes/Utility/File/ProcessingConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 = [],
Expand Down
12 changes: 11 additions & 1 deletion Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Documentation/Developer/Images.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4be1099

Please sign in to comment.