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
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
This is a weird SVG. If you look at the header, it has the ViewBox set to be:
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:
So 74MB and 0.3s to make this:
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:
90MB and 0.6s to make:
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.