Project

General

Profile

Actions

Feature #75191

closed

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

Added by christian rauch about 8 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Image Generation / GIFBUILDER
Target version:
-
Start date:
2016-03-19
Due date:
% Done:

100%

Estimated time:
PHP Version:
Tags:
Complexity:
medium
Sprint Focus:

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
);
Actions

Also available in: Atom PDF