Skip to content

Commit

Permalink
[BUGFIX] Add option to process SVG files
Browse files Browse the repository at this point in the history
Resolves: #782
  • Loading branch information
twoldanski committed Sep 30, 2024
1 parent 21cdcd4 commit d454945
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Classes/DataProcessing/FilesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions Classes/DataProcessing/GalleryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FileUtility
*/
protected array $errors = [];
protected Features $features;
protected bool $allowSvgProcessing = false;

public function __construct(
?ContentObjectRenderer $contentObjectRenderer = null,
Expand All @@ -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<string,mixed> $dimensions
* @return array<string, mixed>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d454945

Please sign in to comment.