identify 6.9.10 is too slow for SVG files

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Locked
hackerb9
Posts: 5
Joined: 2018-12-07T01:06:31-07:00
Authentication code: 1152

identify 6.9.10 is too slow for SVG files

Post by hackerb9 »

Hi, I'm using identify to quickly sort through many files to detect which are valid images, but it bogs down on SVG files.

Code: Select all

$ time identify jerucross.svg 
jerucross.svg SVG 1000x1000 1000x1000+0+0 8-bit sRGB 26577B 0.000u 0:00.010

real    0m23.108s
user    0m22.620s
sys     0m0.396s
I have rsvg-convert installed and it is plenty fast. I double checked with convert -list delegate that ImageMagick was calling rsvg-convert and it said it was. However, using convert -verbose showed it was secretly calling inkscape! (Why isn't Inkscape listed for my delegate?)

I came across an old post by snigbo saying one could prefix RSVG: to force processing with rsvg, however that did not work. What did work for me, surprisingly, was processing the file as MSVG:

Code: Select all

time identify msvg:jerucross.svg
msvg:jerucross.svg=>jerucross.svg MSVG 1000x1000 1000x1000+0+0 16-bit sRGB 2326B 0.010u 0:00.000

real    0m0.023s
user    0m0.016s
sys     0m0.004s
As you can see, it runs three orders of magnitude faster! However, it is not a good solution for me because I do not know if all SVG files can be treated as MSVG.

By the way, this also appears to be a bug with convert -ping which should not ask inkscape to render the whole image just to get image attributes:

Code: Select all

$ time convert -ping jerucross.svg info:
jerucross.svg SVG 1000x1000 1000x1000+0+0 8-bit sRGB 26577B 0.000u 0:00.000

real    0m22.696s
user    0m22.160s
sys     0m0.436s
I'm using ImageMagick on Debian GNU/Linux:
convert -version wrote:Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib
I've had this problem with all SVG files to varying degrees, but I'll upload the one I used, jerucross.svg, in the next post as the time difference is quite stark.

hackerb9
Posts: 5
Joined: 2018-12-07T01:06:31-07:00
Authentication code: 1152

Re: identify 6.9.10 is too slow for SVG files

Post by hackerb9 »

[Redacted]
Last edited by hackerb9 on 2019-11-20T04:02:21-07:00, edited 1 time in total.

hackerb9
Posts: 5
Joined: 2018-12-07T01:06:31-07:00
Authentication code: 1152

jerucross.svg

Post by hackerb9 »

Code: Select all

<svg xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     viewBox="-500 -500 1000 1000"
     style='background-color: black; stroke: none; fill: red'>

  <!-- (Pseudo)Fractal Jerusalem Cross. Based on a tweet by @theusotsuki.  -->
  <!-- B9 March 20, 2019 -->


  <defs>
    <polyline id="halfleg"
	      points="-1,0 50,0 50,50 50,400 125,400 125,500 -1,500"
	      stroke-width="0pt"
	      foo-vector-effect="non-scaling-stroke"/>
    <g id="leg">
      <use xlink:href="#halfleg" />
      <use xlink:href="#halfleg" transform="scale(-1,1)"/>
    </g>
    
    <g id="cross">
      <use xlink:href="#leg" />
      <use xlink:href="#leg" transform="rotate(90)" />
      <use xlink:href="#leg" transform="rotate(-90)" />
      <use xlink:href="#leg" transform="rotate(180)" />
    </g>

    <g id="iterate" transform="scale(.25)">
      <use xlink:href="#cross" transform="translate(-900, -900) " />
      <use xlink:href="#cross" transform="translate(900, 900)" />
      <use xlink:href="#cross" transform="translate(-900, 900)" />
      <use xlink:href="#cross" transform="translate(900, -900)" /> 
    </g>


    <g id="iterate2" transform="scale(.25)">
      <use xlink:href="#iterate" transform="translate(-900, -900) " />
      <use xlink:href="#iterate" transform="translate(900, 900)" />
      <use xlink:href="#iterate" transform="translate(-900, 900)" />
      <use xlink:href="#iterate" transform="translate(900, -900)" /> 
    </g>

    <g id="iterate3" transform="scale(.25)">
      <use xlink:href="#iterate2" transform="translate(-900, -900) " />
      <use xlink:href="#iterate2" transform="translate(900, 900)" />
      <use xlink:href="#iterate2" transform="translate(-900, 900)" />
      <use xlink:href="#iterate2" transform="translate(900, -900)" /> 
    </g>

      <g id="iterate4" transform="scale(.25)">
      <use xlink:href="#iterate3" transform="translate(-900, -900) " />
      <use xlink:href="#iterate3" transform="translate(900, 900)" />
      <use xlink:href="#iterate3" transform="translate(-900, 900)" />
      <use xlink:href="#iterate3" transform="translate(900, -900)" /> 
    </g>
  </defs>	

  <use xlink:href="#cross" />
  <use xlink:href="#iterate" />
  <use xlink:href="#iterate2" />
  <use xlink:href="#iterate3" />
  <use xlink:href="#iterate4" />
</svg>

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: identify 6.9.10 is too slow for SVG files

Post by snibgo »

hackerb9 wrote:I double checked with convert -list delegate that ImageMagick was calling rsvg-convert and it said it was.
This tells you what external delegates are in your various delegates.xml files. It does not tell you whether the delegate will be used.
hackerb9 wrote:However, using convert -verbose showed it was secretly calling inkscape! (Why isn't Inkscape listed for my delegate?)
Yes, "-verbose" tells you what is happening. When Inkscape is on your system path, it will be used, overriding delegates.xml.

MSVG is IM's own rasterizer for SVG. It is fast but can't process the more advanced features of SVG.
hackerb9 wrote:By the way, this also appears to be a bug with convert -ping which should not ask inkscape to render the whole image just to get image attributes:
Why not? The only way IM can get image attributes, eg width and height, is by rasterizing it.

Inkscape is slower than RSVG or MSVG. This is because Inkscape takes time to start up. But Inkscape is generally the most accurate method. If you want to use another method, ensure that Inkscpae is not on your system path.
snibgo's IM pages: im.snibgo.com

Locked