how to set quality when convert svg to 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
amir123
Posts: 9
Joined: 2017-03-08T04:39:11-07:00
Authentication code: 1151

how to set quality when convert svg to png

Post by amir123 » 2017-03-08T04:49:23-07:00

Hi magick developers team
I convert svg file to png
That's ok to convert but when I see png, it is very bad quality of text element!
How to set magick setting to view nice qulaity of png file?

my svg code:

Code: Select all

<svg width="500" height="300" xmlns="http://www.w3.org/2000/svg">
  <g transform="scale(1)">
    <text style="dominant-baseline:hanging; font-family:'Tahoma';fill:rgb(51, 51, 51);direction:ltr;font-size:50pt;font-weight:400;font-style:normal;text-decoration:none;" x="167" y="174" transform="rotate(0 167 174)">12345</text>
  </g>
</svg>
png file converted with svg library:
Image

png file converted with magick:
Image

my code here:

Code: Select all

            try
            {

                ImageMagick.MagickImage image = new ImageMagick.MagickImage(@"c:\1.svg");
                image.Format = ImageMagick.MagickFormat.Png;

                image.Settings.TextAntiAlias = true;

                ImageMagick.MagickColor mc = new ImageMagick.MagickColor(Color.Transparent);
                image.Transparent(mc);

                ImageMagick.QuantizeSettings a = new ImageMagick.QuantizeSettings();
                a.DitherMethod = ImageMagick.DitherMethod.Riemersma;

                image.Write(@"c:\Magick.png");
            }
            catch (Exception ex)
            {

            }

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

Re: how to set quality when convert svg to png

Post by snibgo » 2017-03-08T08:29:05-07:00

wrote:... but when I see png, it is very bad quality of text element!
What is wrong with it? The quality looks good to me.
snibgo's IM pages: im.snibgo.com

User avatar
magick
Site Admin
Posts: 10692
Joined: 2003-05-31T11:32:55-07:00

Re: how to set quality when convert svg to png

Post by magick » 2017-03-08T09:01:16-07:00

You want to supersample, from the command-line it looks like this:
  • convert -density 400 image.svg -resize 25% image.jpg

amir123
Posts: 9
Joined: 2017-03-08T04:39:11-07:00
Authentication code: 1151

Re: how to set quality when convert svg to png

Post by amir123 » 2017-03-08T23:45:22-07:00

snibgo wrote:
2017-03-08T08:29:05-07:00
wrote:... but when I see png, it is very bad quality of text element!
What is wrong with it? The quality looks good to me.
Open two images and zoom in
svg library convert with good anti alias but magick is not good!
magick has indendaton on text!

amir123
Posts: 9
Joined: 2017-03-08T04:39:11-07:00
Authentication code: 1151

Re: how to set quality when convert svg to png

Post by amir123 » 2017-03-08T23:54:28-07:00

magick wrote:
2017-03-08T09:01:16-07:00
You want to supersample, from the command-line it looks like this:
  • convert -density 400 image.svg -resize 25% image.jpg
I use this code on C# .net but when I set resize, crashed!

my code here:

Code: Select all

            try
            {

                ImageMagick.MagickImage image = new ImageMagick.MagickImage(@"c:\1.svg");
                image.Format = ImageMagick.MagickFormat.Png;
                ImageMagick.Density de = new ImageMagick.Density(400, 400);
                image.Density = de;

                ImageMagick.Percentage pe = new ImageMagick.Percentage(25);
                image.Resize(pe);

                image.Settings.TextAntiAlias = true;

                ImageMagick.MagickColor mc = new ImageMagick.MagickColor(Color.Transparent);
                image.Transparent(mc);

                ImageMagick.QuantizeSettings a = new ImageMagick.QuantizeSettings();
                a.DitherMethod = ImageMagick.DitherMethod.Riemersma;

                image.Write(@"c:\Magick.png");
            }
            catch (Exception ex)
            {

            }
I think text anti alias on magick is sharp but I need smoothed or crisp like svg library
I don't need to change size of image.
default resolution on my project is 72 and my size is fixed.
can you help me?

amir123
Posts: 9
Joined: 2017-03-08T04:39:11-07:00
Authentication code: 1151

Re: how to set quality when convert svg to png

Post by amir123 » 2017-03-09T00:11:10-07:00

png file converted with magick and zoom 600%
Image


png file converted with SVG Rendering Library and zoom 600%
Image


I think magick use hard pen and svg library use soft pen!
I think text anti alias on magick is sharp but I need smoothed or crisp like svg library
help me plz
Last edited by amir123 on 2017-03-09T01:20:08-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 22109
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: how to set quality when convert svg to png

Post by fmw42 » 2017-03-09T00:28:35-07:00

why are you dithering? seems to me that would make the edges more aliased

have you tried the command given by Magick for supersampling in the command line?

Imagemagick uses delegates to convert svg to raster such as png. The best delegates are Inkscape first and then RSVG and then IM internal MSVG (XML). Which are you using?

User avatar
fmw42
Posts: 22109
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: how to set quality when convert svg to png

Post by fmw42 » 2017-03-09T00:40:49-07:00

dixita wrote:
2017-03-09T00:39:53-07:00
Hey i just convert my gravtar in svg to png. but i cant go back.. any solution??
Sorry, I do not understand the question! What is "gravtar"?

Once you convert svg to png and delete the svg, you cannot go back. Imagemagick is a raster processor. It does not vectorize! So you cannot effectively do png to svg. See http://www.imagemagick.org/Usage/formats/#vector

amir123
Posts: 9
Joined: 2017-03-08T04:39:11-07:00
Authentication code: 1151

Re: how to set quality when convert svg to png

Post by amir123 » 2017-03-09T01:09:49-07:00

fmw42 wrote:
2017-03-09T00:28:35-07:00
why are you dithering? seems to me that would make the edges more aliased
I remove it from my code but qulity in the edges is bad.
fmw42 wrote:
2017-03-09T00:28:35-07:00
have you tried the command given by Magick for supersampling in the command line?
I use command line by this code:
magick wrote:
2017-03-08T09:01:16-07:00
You want to supersample, from the command-line it looks like this:
  • convert -density 400 image.svg -resize 25% image.jpg
But I don't need resize my image with high resolution.
fmw42 wrote:
2017-03-09T00:28:35-07:00
Imagemagick uses delegates to convert svg to raster such as png. The best delegates are Inkscape first and then RSVG and then IM internal MSVG (XML). Which are you using?
I use SVG Rendering Library
https://www.nuget.org/packages/Svg/

Furthermore I need c# .net to convert svg to png
I make svg string at runtime and convert it on the fly to png
I think command line is bad solution to convert svg string to memory stream image
What's your solution?

User avatar
fmw42
Posts: 22109
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: how to set quality when convert svg to png

Post by fmw42 » 2017-03-09T01:46:36-07:00

Imagemagick is limited to the use of Inkscape, RSVG or MSVG(XML). So if you use Imagemagick such as

Code: Select all

convert -density 400 image.svg image.jpg
It will use whichever svg renderer you have installed. You can see which one using

Code: Select all

convert -list format
For me, I have:

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.40.16)

I am told that Inkscape is better.

amir123
Posts: 9
Joined: 2017-03-08T04:39:11-07:00
Authentication code: 1151

Re: how to set quality when convert svg to png

Post by amir123 » 2017-03-09T02:34:30-07:00

fmw42 wrote:
2017-03-09T01:46:36-07:00
Imagemagick is limited to the use of Inkscape, RSVG or MSVG(XML). So if you use Imagemagick such as

Code: Select all

convert -density 400 image.svg image.jpg
It will use whichever svg renderer you have installed. You can see which one using

Code: Select all

convert -list format
For me, I have:

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.40.16)

I am told that Inkscape is better.
for me is
SVG SVG rw+ Scalable Vector Graphics (RSVG 2.40.50)

I test with inkscape and conversion is good
Lock the topic

Good luck magick Team

Post Reply