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 #1

Updated by christian rauch about 8 years ago

  • Assignee set to Frans Saris
Actions #2

Updated by Frans Saris about 8 years ago

Out of curiosity, what's your use-case to convert svg to PNG?

Actions #3

Updated by christian rauch about 8 years ago

I want our Editors to upload Icons for a Product Detail Page in Svg Format but this Website still has to work on IE8 (yay!) and therefore I need a png Fallback. I could of course add a second File Reference and have them upload the same Icon in PNG Format but I thought that I can do this on the Server.

I already tried a fake crop and a fake mask. The Icon then is converted to png but somehow it's rendered horribly.

Actions #4

Updated by Frans Saris about 8 years ago

But you tested it without crop and the quality is then okay?

If we add such a config option to core it will only be for master (TYPO3 8), not for 7 as we don't backport features to stable releases.

Actions #5

Updated by christian rauch about 8 years ago

Yes, then the quality is good...

I know IE8 is a legacy Browser and supporting it becomes less and less critical but I could imagine that Typo3 is also used to generate Content for other Systems that don't support svgs. Maybe Word Documents or something like that.

For now I'll help myself with an Xclass as we have to use the LTS Version and still have a bunch of huge pibase Extensions which we didn't port to extbase.

Also I didn't dig to deep into the quality issues with the mask and crop workaround.

Actions #6

Updated by Oliver Hader almost 8 years ago

  • Tracker changed from Bug to Feature
  • Complexity changed from easy to medium
Actions #7

Updated by Frans Saris over 7 years ago

  • Assignee deleted (Frans Saris)
Actions #8

Updated by Markus Hölzle about 7 years ago

Hey there,
can we think about this issue again?
It is still impossible to convert SVG graphics to PNG images.
But for example big and complex SVG graphics make the iPhone to crash... So we just need a PNG fallback for modern browsers.
Any chance to get this into the core?

Actions #9

Updated by Riccardo De Contardi about 6 years ago

  • Category set to Image Generation / GIFBUILDER
Actions #10

Updated by Gerrit Code Review about 4 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63611

Actions #11

Updated by Gerrit Code Review almost 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63611

Actions #12

Updated by Gerrit Code Review almost 4 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63611

Actions #13

Updated by Gerrit Code Review almost 4 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63611

Actions #14

Updated by Gerrit Code Review almost 4 years ago

Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64947

Actions #15

Updated by Gerrit Code Review almost 4 years ago

Patch set 2 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64947

Actions #16

Updated by Gerrit Code Review almost 4 years ago

Patch set 3 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/64947

Actions #17

Updated by Benni Mack almost 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #18

Updated by Benni Mack over 3 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF