craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 626 forks source link

Broken thumb for SVGs without both height and width #3191

Open timkelty opened 6 years ago

timkelty commented 6 years ago

SVGs don't always have a height/width attribute. If they don't the thumbnail doesn't seem to work.

screen shot 2018-08-10 at 12 38 41 pm

Example: tiger.svg.zip

brandonkelly commented 6 years ago

@andris-sevcenko Probably unrelated, but if you generate a thumb/transform with that tiger.svg, Craft will produce an invalid SVG, with two height attributes on the <svg> tag, because the original SVG already has a height attribute but no width.

Even if I manually fix that, Chrome and macOS just show a blank image for the transformed SVGs, which seems like the root issue here.

screen shot 2018-08-10 at 1 36 29 pm
andris-sevcenko commented 6 years ago

If you want a thumbnail or any geometry operations performed, you need to have a width/height attribute pair or a viewBox attribute.

If you run identify tiger.svg, you get tiger.svg SVG 0x800 0x800+0+0 16-bit sRGB 100459B 0.020u 0:00.029

If you try to coax ImageMagick into giving you more info than "0x800" with identify -verbose tiger.svg, you get identify: must specify image size '/var/folders/br/qw4t5tw96b90yqy_vdvv80sc0000gn/T/magick-36009puUk7rSqcvoE' @ error/mvg.c/ReadMVGImage/184.

Theoretically, you could probably analyze the SVG file, trace all the paths and figure out what the real width would be for a height of 800, but let's be real here - that's probably an overkill.

brandonkelly commented 6 years ago

@andris-sevcenko still probably worth looking into why the SVG can be viewed in macOS/Chrome initially, but not after going through our transform process.