skip to Main Content

I met an issue when I convert this SVG to image and I cannot workaround, does anyone know the possible reason?

Error:

thread '<unnamed>' panicked at 'Cairo error "out of memory"', /build/librsvg-RSSQuy/librsvg-2.48.9/vendor/cairo-rs/src/enums.rs:274:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5

SVG URL: https://upload.wikimedia.org/wikipedia/commons/5/56/Carreteras_de_Pamplona.svg

Code:

image = pyvips.Image.new_from_file(svg_name, memory=True, fail=True)
image.write_to_file(jpg_name)

Environments:

  • Ubuntu 20.04 LTS (64G RAM)
  • pyvips 2.2.1
  • libvips-dev/focal 8.9.1-2 amd64
  • libvips-doc/focal 8.9.1-2 all
  • libvips-tools/focal 8.9.1-2 amd64
  • libvips42/focal,now 8.9.1-2 amd64 [installed]

2

Answers


  1. You are getting an "out of memory" error, which is actually no surpise with that SVG, as it is pretty large. I suggest just downloading/saving that file to your pc and converting it to a PNG with something like Inkscape or Adobe Illustrator.

    If you want a solution to the problem itself: get more RAM, either through closing other programs or upgrading your hardware/doing it on another PC

    Login or Signup to reply.
  2. This is a weird SVG. If you look at the header, it has the ViewBox set to be:

       viewBox="-269795.54 4657840.8 1466.8124 1213.8088"
    

    And it gives your librsvg terrible indigestion.

    I tried with librsvg in ubuntu 22.04 and it seems to work, but you get a very screwy image:

    $ /usr/bin/time -f %M:%e vips copy Carreteras_de_Pamplona.svg x.jpg
    74176:0.28
    

    So 74MB and 0.3s to make this:

    enter image description here

    A very tall, thin image, with your map as the tiny square at the bottom. If you zoom and crop, you can get some detail:

    $ /usr/bin/time -f %M:%e vips crop Carreteras_de_Pamplona.svg[scale=90] x.png 0 29972 1010 836
    91368:0.57
    

    90MB and 0.6s to make:

    enter image description here

    You can’t zoom it any further, unfortunately, because librsvg won’t render an image with any axis over 32k pixels.

    If possible, I would go back to the SVG source and regenerate the file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search