Best aspose library for converting svg to png, jpeg,tiff image file formats

What is the best Aspose library to convert svg files into raster image file formats png, jpeg, tiff? We have tried the following libraries for conversion aspose.svg, aspose.imaging, aspose.html.
We are using google fonts in the svg. Aspose.html is the only library that considers the font file while converting to png / jpeg. But it doesn’t have any option to set compression options to convert without losing the quality.
We are looking for a suggestion to use the correct library which respects the font file included in the svg file and also converts with the best quality.

@mkumars6

Could you please share your sample SVG document and the expected compression options details for our reference? We will log a ticket in our issue tracking system for the feasibility analysis and share our feedback with you.

Hi,

I am attaching the following files for your analysis.

Source svg file - sample.svg
converted png file using my code with aspose.html - sample.png
converted png file using online aspose link
(SVG to PNG Converter | Convert SVG to PNG online for free) - sample_asposeonline.png

The quality of the conversion using my code is less compared to the online conversion. I am noticing the online aspose tool increases the png image dimensions. I wanted to retain the image dimensions. In this case it is 384 * 384 px. I am using an evaluation version of aspose.html 23.4.0 and .NET 6 application.

Please let me know if any details required.upload.zip (37.9 KB)

@mkumars6

Thanks for sharing the sample file. Can you please also share the code snippet that you used for the conversion? We will further proceed to assist you accordingly.

Hi @asad.ali,

Please find below the code snippet for converting from svg to other formats

//png
var pngOptions = new ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png)
{
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
HorizontalResolution = 300,
VerticalResolution = 300
};
if (height != 0 && width != 0)
pngOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(width, height), new Margin(1, 1, 1, 1)); //height and width are the height and width of the svg
pngOptions.Text.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Converter.ConvertSVG(document, pngOptions, markAsposeHtmlPath.Replace(".svg", “.png”));

//jpeg
var jpegOptions = new ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Jpeg)
{
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
HorizontalResolution = 300,
VerticalResolution = 300
};
if (height != 0 && width != 0)
jpegOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(width, height), new Margin(1, 1, 1, 1)); //height and width are the height and width of the svg
jpegOptions.Text.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Converter.ConvertSVG(document, jpegOptions, markAsposeHtmlPath.Replace(".svg", “.jpeg”));

//tiff
var tiffOptions = new ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Tiff)
{
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
HorizontalResolution = 300,
VerticalResolution = 300
};
if (height != 0 && width != 0)
tiffOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(width, height), new Margin(1, 1, 1, 1)); //height and width are the height and width of the svg
tiffOptions.Text.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Converter.ConvertSVG(document, tiffOptions, markAsposeHtmlPath.Replace(".svg", “.tiff”));

@mkumars6

We are checking it and will get back to you shortly.

Hi @asad.ali,

Is there any update on this query?

@mkumars6

Looks like you were trying to perform the conversion using a trial version of the API. Please check the attached sample output PNG that we generated in our environment using Aspose.HTML for .NET 23.9 with a valid license and the below code snippet:

Aspose.Html.Dom.Svg.SVGDocument document = new Aspose.Html.Dom.Svg.SVGDocument(dataDir + "sample.svg");
var pngOptions = new Aspose.Html.Saving.ImageSaveOptions(Aspose.Html.Rendering.Image.ImageFormat.Png)
{
    SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
    HorizontalResolution = 300,
    VerticalResolution = 300
};
//if (height != 0 && width != 0)
//pngOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(width, height), new Margin(1, 1, 1, 1)); //height and width are the height and width of the svg
pngOptions.Text.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Aspose.Html.Converters.Converter.ConvertSVG(document, pngOptions, dataDir + "output.png");

output.png (80.8 KB)

You can please obtain a temporary license which will be valid for 30-days in order to evaluate the API without any limitations. In case you still face any issues, please let us know.

Hi @asad.ali,

Thank you for sharing the output file. I saw the output.png is having the dimension of 2480 X 3508 px. But the actual svg is having the dimension of 384 X 384 px. Is it possible to update the below line and generate a PNG of dimension 384 X 384 px and share us the output? Basically we want the png image dimension to be matching with svg dimension.

pngOptions.PageSetup.AnyPage = new Aspose.Html.Drawing.Page(new Aspose.Html.Drawing.Size(384, 384));

@mkumars6

Here is the attached output with new dimensions:

output.png (5.7 KB)