Feature #75191
closedConverting svg to png not possible without cropping or masking the image
100%
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 );
Updated by Frans Saris over 8 years ago
Out of curiosity, what's your use-case to convert svg to PNG?
Updated by christian rauch over 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.
Updated by Frans Saris over 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.
Updated by christian rauch over 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.
Updated by Oliver Hader over 8 years ago
- Tracker changed from Bug to Feature
- Complexity changed from easy to medium
Updated by Markus Hölzle over 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?
Updated by Riccardo De Contardi over 6 years ago
- Category set to Image Generation / GIFBUILDER
Updated by Gerrit Code Review over 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
Updated by Gerrit Code Review over 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
Updated by Gerrit Code Review over 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
Updated by Gerrit Code Review over 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
Updated by Gerrit Code Review over 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
Updated by Gerrit Code Review over 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
Updated by Gerrit Code Review over 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
Updated by Benni Mack over 4 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 5275e76e4ae7e00a0bce59b8d458e547e427b92b.
Updated by Benni Mack almost 4 years ago
- Status changed from Resolved to Closed