Compose.jl icon indicating copy to clipboard operation
Compose.jl copied to clipboard

Generated SVG incompatible with ImageMagick (not standards-compliant?)

Open divilian opened this issue 4 years ago • 7 comments

When I take any .svg file produced by the SVG() function, and try to run the ImageMagick "convert" utility on it (to, say, convert it to a frame of what will become an animated GIF), I get these errors:

shell> convert tomato.svg tomato.gif
convert-im6.q16: unrecognized color `context-stroke' @ warning/color.c/GetColorCompliance/1052.
convert-im6.q16: unable to open image `context-stroke': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
convert-im6.q16: non-conforming drawing primitive definition `stroke' @ error/draw.c/DrawImage/3265.

(The code I used to produce tomato.svg is:

composition = compose(compose(context(), rectangle()), fill("tomato"))
draw(SVG("tomato.svg", 4cm, 4cm), composition)

i.e., the example directly from the Compose.jl documentation. I'm running Julia 1.4.1 with Compose v0.8.2.)

divilian avatar May 14 '20 18:05 divilian

In Compose context-stroke is used for marker arrows, and markers are defined at the top of the svg file (whether you use them or not). You could manually edit the svg file, or perhaps ask at ImageMagick issues if it's a bug, or on their To Do list, or they have a workaround. That would help us to decide our way forward.

Mattriks avatar May 14 '20 23:05 Mattriks

does your example output pass an SVG validator?

bjarthur avatar May 18 '20 22:05 bjarthur

It does not pass the link you posted, no. I get: https://validator.w3.org/unicorn/check?ucn_uri=stephendavies.org%2Ftomato.svg&ucn_task=conformance#

divilian avatar May 19 '20 02:05 divilian

You can't test an svg v1.2 file (tomato.svg) using an svg 1.1 validator. This validator will pass for svg 1.2: https://validator.nu/?doc=http%3A%2F%2Fstephendavies.org%2Ftomato.svg. Green box at the bottom says "the document validates according to the specified schema" (i.e. schema =v1.2). The warning in yellow can be ignored.

Mattriks avatar May 19 '20 05:05 Mattriks

ah, got it. Thanks @Mattriks. So if I understand what I'm reading then, this demonstrates that the issue is actually with ImageMagick, not Compose.jl. (Somebody tell me if I'm misinterpreting! New to all this.)

divilian avatar May 19 '20 14:05 divilian

context-fill and context-stroke are available in svg 1.2 (i.e. leading up to svg 2). Inkscape supports these features (https://inkscape.org/release/inkscape-0.92/ - scroll down to near the bottom of that page - under the header "SVG and CSS"), and so does Compose. But many web browsers still only support svg 1.1. So the question is: does ImageMagick support svg 1.2, or is it on their To Do list?

Note: Apparently ImageMagick will use Inkscape if it's available, see e.g. https://github.com/ImageMagick/ImageMagick/discussions/1880

Mattriks avatar May 19 '20 17:05 Mattriks

Did you investigate converting a Compose svg file using ImageMagick with Inkscape? If so, please write about your findings here, to help other users.

Mattriks avatar May 29 '20 11:05 Mattriks