Issue Feature Closed

#75191Converting svg to png not possible without cropping or masking the image

christian rauch 03/19/16, 13:30 updated 12/22/20, 11:08

Description

I tried to write a viewhelper which generates a Fallback Png for SVG Images. I added ‘fileExtension’ => ‘png’ to the processing Instructions but it gets ignored because of the following condition in LocalCropScaleMaskHelper.php

            // SVG
            if ($croppedImage === null && $sourceFile->getExtension() === 'svg') {
                $newDimensions = $this->getNewSvgDimensions($sourceFile, $configuration, $options, $gifBuilder);
                $result = array(
                    0 => $newDimensions['width'],
                    1 => $newDimensions['height'],
                    3 => '' // no file = use original
                );

            // all other images
            }

First I thought about extending the condition like that

 if ($croppedImage === null && $sourceFile->getExtension() === 'svg' && $configuration['fileExtension'] !=='svg') {

But this will always be true as the fileExtension will be one of gif, jpg, or png if not explicitly set…

Would it be possible to add an extra configuration parameter like forceSvgConvert or something like that

The condition could then look like this

 if ($croppedImage === null && $sourceFile->getExtension() === 'svg' && !$configuration['forceSvgConvert']) {

And one could use processing Instructions like this to force the generation of a Fallback Png for a svg image

$processingInstructions = array(
  'width' => $width,
  'height' => $height,
  'minWidth' => $minWidth,
  'minHeight' => $minHeight,
  'maxWidth' => $maxWidth,
  'maxHeight' => $maxHeight,
  'additionalParameters' => ' -background none',
  'fileExtension' => 'png',
  'forceSvgConvert' => true
);

Reviews 2