Converting a "complex" SVG to a PNG

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
Robar
Posts: 8
Joined: 2013-12-11T00:26:12-07:00
Authentication code: 6789

Converting a "complex" SVG to a PNG

Post by Robar »

I'm quite new to ImageMagick and want to convert complex SVGs to PNG. I've tested several SVGs with ImageMagick and Batik.

Commands I used:

ImageMagick:

Code: Select all

 E:\xxx\ImageMagick-6.8.7-Q16>convert -size 400x400 -background none "E:\xxx\svgTestSimple.svg" "E:\xxx\svgTestSimple_magick.png"
Batik:

Code: Select all

E:\xxx\batik-1.7>java -jar batik-rasterizer.jar -w 400 -h 400 "E:\xxx\svgTestSimple.svg" -d "E:\xxx\svgTestSimple_batik.png"
Results:

Cube (included SVG + text):
SVG: https://devpublic.blob.core.windows.net ... /Empty.svg
ImageMagick: https://devpublic.blob.core.windows.net ... magick.png (not acceptable)
Batik: https://devpublic.blob.core.windows.net ... _batik.png (acceptable)

Shapes (image + mask):
SVG: https://devpublic.blob.core.windows.net ... shapes.svg
ImageMagick: https://devpublic.blob.core.windows.net ... magick.png (not acceptable)
Batik: https://devpublic.blob.core.windows.net ... _batik.png (acceptable)

Simple (2 circles + image):
SVG: https://devpublic.blob.core.windows.net ... Simple.svg
ImageMagick: https://devpublic.blob.core.windows.net ... magick.png (acceptable)
Batik: https://devpublic.blob.core.windows.net ... _batik.png (acceptable)

Complex (circle + image + mask + displacement map):
SVG: https://devpublic.blob.core.windows.net ... vgTest.svg
ImageMagick: https://devpublic.blob.core.windows.net ... magick.png (acceptable)
Batik: https://devpublic.blob.core.windows.net ... _batik.png (almost acceptable, the displacement map don't work)

Problem

ImageMagick
All I want to do is to convert a SVG to PNG with C# .NET. Possible solutions are using ImageMagick.NET (http://imagemagick.codeplex.com/) OR the online service Blitline (uses ImageMagick -> http://blitline.com/), but it should be possible to convert the given SVG (see above) to PNG.

Batik
Using Batik is quite cumbersome, because I would need to start a process which also starts the JVM so that the JAR file can be executed (resource intensive (RAM, CPU)).

My question is, is there any ImageMagick solution to achieve the same output as with Batik (Note: I can't change the input SVG)? Following things seem not work quite properly: SVGText with text-anchor="middle", mask and including other SVGs.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Converting a "complex" SVG to a PNG

Post by dlemstra »

As stated here 'viewtopic.php?f=3&t=24611#p105829', I will try to see if I can change the svg handler for the windows distribution. I would also advise you to use the new C# api Magick.NET (https://magick.codeplex.com).
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Robar
Posts: 8
Joined: 2013-12-11T00:26:12-07:00
Authentication code: 6789

Re: Converting a "complex" SVG to a PNG

Post by Robar »

dlemstra wrote:As stated here 'viewtopic.php?f=3&t=24611#p105829', I will try to see if I can change the svg handler for the windows distribution. I would also advise you to use the new C# api Magick.NET (https://magick.codeplex.com).
I just tried it with Magick.NET (yes I know you havn't changed the svg handler yet), same (not acceptable) output. And I also tried the online service of Blitline (http://www.blitline.com/docs/gist_runne ... id=5274643) altough I don't know if they use "librsvg". I only read on their website that they use ImageMagick in the background.

If I try ImageMagick local on my computer, windows 8 only lists the following SVG handlers:
MSVG SVG rw+ ImageMagick's own SVG internal renderer
SVG SVG rw+ Scalable Vector Graphics (XML 2.9.0)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (XML 2.9.0)

Do you think that it should work with "librsvg"?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Converting a "complex" SVG to a PNG

Post by dlemstra »

You have to wait till I managed to get librsvg to work in the windows distribution (or failed ;( ). Once this change has been made it will automatically be available in Magick.NET.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Robar
Posts: 8
Joined: 2013-12-11T00:26:12-07:00
Authentication code: 6789

Re: Converting a "complex" SVG to a PNG

Post by Robar »

dlemstra wrote:You have to wait till I managed to get librsvg to work in the windows distribution (or failed ;( ). Once this change has been made it will automatically be available in Magick.NET.
Any updates yet?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Converting a "complex" SVG to a PNG

Post by dlemstra »

I completely forgot about this post. The current version of Magick.NET and the current windows distribution are using librsvg to parse SVG files. Not all your images where working but it looked like a bug in librsvg. Feel free to post images that you are using and are not working here and maybe I can track down the bug in librsvg.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Robar
Posts: 8
Joined: 2013-12-11T00:26:12-07:00
Authentication code: 6789

Re: Converting a "complex" SVG to a PNG

Post by Robar »

dlemstra wrote:I completely forgot about this post. The current version of Magick.NET and the current windows distribution are using librsvg to parse SVG files. Not all your images where working but it looked like a bug in librsvg. Feel free to post images that you are using and are not working here and maybe I can track down the bug in librsvg.
First of all: Big thx for MagickNet, with librsvg it now seems to work way better than before.

I've just tested a few of my SVGs and noticed that the SVGText with text-anchor="middle" still doesn't work properly. Only the right half of the SVGText will be shown.

SVG: https://devpublic.blob.core.windows.net ... s/text.svg
MagickNet-Output: https://devpublic.blob.core.windows.net ... ck_neu.png
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Converting a "complex" SVG to a PNG

Post by dlemstra »

I can reproduce the problem and this looks like a bug in librsvg. I will try to track down this bug and get back to you. Not sure when I will have some time to do that.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply