Compose.jl
Compose.jl copied to clipboard
Generated SVG incompatible with ImageMagick (not standards-compliant?)
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.)
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.
does your example output pass an SVG validator?
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#
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.
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.)
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
Did you investigate converting a Compose svg file using ImageMagick with Inkscape? If so, please write about your findings here, to help other users.