Matt Coady
Matt Coady

Reputation: 3856

Imagemagick: non-conforming drawing primitive definition `path'

SVG in question (I cleaned out anything that wasn't related to the issue):

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 330 360">

  <defs>
    <path id="SVGID_1_" d="M166.3,7.4c-1.2,0-2.4,0-3.6,0c-10.4,0.2-20.9,1.3-26.9,3.8c-31.3,15.1-36.7,36.2-35.4,65.6"/>
  </defs>

  <clipPath id="SVGID_2_">
    <use xlink:href="#SVGID_1_"/>
  </clipPath>

  <path
    clip-path="url(#SVGID_2_)"
    d="M166.7 1.5S129-4.3 112.9 3.8c-7.3 3.7-12 11.7-15.5 19.1-5.2 11.2-6.8 36.4-6.8 36.4l15.9 11.4c.2-8.2 6.9-17.4 10.5-25.1 3.9-8.2 1.1-6.7 3.6-8.2 15.4-5.9 30.5-1 46 0 16.5 1.1 33.4-6.4 46 0 2.6 1.5 1.6-.6 3.6 8.2 1.6 6.8 12 18.8 10.5 25.1l15.9-11.4s-1.6-25.2-6.8-36.4c-3.4-7.4-8.2-15.4-15.5-19.1-15.9-8.1-53.6-2.3-53.6-2.3z"/>

</svg>

When I run this file through Imagemagick 7.0.7-22 Q16 x86_64 using identify:

magick identify -verbose clipPath.svg

The output ends with this:

identify: non-conforming drawing primitive definition `path' @ error/draw.c/DrawImage/3284.

I've narrowed down the issue to line 12:

clip-path="url(#SVGID_2_)"

Cleaning up the SVG isn't really an option because users are going to be able to upload their own SVGs. So the question is:

A) Why is this happening?

B) Is there anything that can be done to Imagemagick that can fix this?

Upvotes: 3

Views: 3461

Answers (2)

emcconville
emcconville

Reputation: 24419

Why is this happening?

As pointed out in the comments, the internal encoder/decoder is converting the SVG to MVG. The use xlink:href="#SVGID_1_" deferment (or would it be called redirect?) is not understood; and so, omitted. If you run the following...

convert clipPath.svg mvg:-

Something like the following would be outputted (whitespace indent added).

push graphic-context
  viewbox 0 0 330 360
  affine 1 0 0 1 0 0
  push defs
    push graphic-context
      path 'M166.3,7.4c-1.2,0-2.4,0-3.6,0c-10.4,0.2-20.9,1.3-26.9,3.8c-31.3,15.1-36.7,36.2-35.4,65.6'
    pop graphic-context
  pop defs
  push clip-path 'SVGID_2_'
  pop clip-path
  push graphic-context
    clip-path 'url(#SVGID_2_)'
    path 'M166.7 1.5S129-4.3 112.9 3.8c-7.3 3.7-12 11.7-15.5 19.1-5.2 11.2-6.8 36.4-6.8 36.4l15.9 11.4c.2-8.2 6.9-17.4 10.5-25.1 3.9-8.2 1.1-6.7 3.6-8.2 15.4-5.9 30.5-1 46 0 16.5 1.1 33.4-6.4 46 0 2.6 1.5 1.6-.6 3.6 8.2 1.6 6.8 12 18.8 10.5 25.1l15.9-11.4s-1.6-25.2-6.8-36.4c-3.4-7.4-8.2-15.4-15.5-19.1-15.9-8.1-53.6-2.3-53.6-2.3z'
  pop graphic-context
pop graphic-context

Notice that clip-path "SVGID_2_" has no content (nothing between push & pop stack), and that defs -> graphic-context is not identifed as a clip-path.

If you rewrite the MVG, it should work as expected.

push graphic-context
  viewbox 0 0 330 360
  affine 1 0 0 1 0 0
  push defs
    push clip-path 'SVGID_2_'
      push graphic-context
        path 'M166.3,7.4c-1.2,0-2.4,0-3.6,0c-10.4,0.2-20.9,1.3-26.9,3.8c-31.3,15.1-36.7,36.2-35.4,65.6'
      pop graphic-context
    pop clip-path
  pop defs

  push graphic-context
    clip-path 'url(#SVGID_2_)'
    path 'M166.7 1.5S129-4.3 112.9 3.8c-7.3 3.7-12 11.7-15.5 19.1-5.2 11.2-6.8 36.4-6.8 36.4l15.9 11.4c.2-8.2 6.9-17.4 10.5-25.1 3.9-8.2 1.1-6.7 3.6-8.2 15.4-5.9 30.5-1 46 0 16.5 1.1 33.4-6.4 46 0 2.6 1.5 1.6-.6 3.6 8.2 1.6 6.8 12 18.8 10.5 25.1l15.9-11.4s-1.6-25.2-6.8-36.4c-3.4-7.4-8.2-15.4-15.5-19.1-15.9-8.1-53.6-2.3-53.6-2.3z'
  pop graphic-context
pop graphic-context

Is there anything that can be done to Imagemagick that can fix this?

Upgrading to ImageMagick 7 will offer some improvements, but as Mark correctly pointed out, you would gain so much more if you switch delegates to a SVG rendering engine that supports advanced features. Read the delegates.xml file shipped with ImageMagick, or online. Examples are given as inline-comments, and I wouldn't be surprised if you already have rsvg, or similar, installed on the system.

Upvotes: 2

Mark Setchell
Mark Setchell

Reputation: 207465

If you run:

identify -list delegate

you will see that ImageMagick delegates dealing with SVG files to rsvg so make sure that is up-to-date.

Also check if any switches or options need to be added to deal with any specific, troublesome SVG elements, and these can be edited into your delegates.xml file.

Upvotes: 1

Related Questions