-
-
Notifications
You must be signed in to change notification settings - Fork 435
Open
Description
Prerequisites
- I have written a descriptive issue title
- I have verified that I am using the latest version of Magick.NET
- I have searched open and closed issues to ensure it has not already been reported
Description
I'm seeing a weird results (png is getting clipped) when converting a particular SVG into PNG using Magick.NET (same issue using imagemagick from the console). The PNG is converted properly if a viewBox is defined in the SVG.
Steps to Reproduce
Run the following code:
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using ImageMagick;
namespace ConsoleApp7
{
class Program
{
static async Task Main()
{
var httpClient = new HttpClient();
// #1 - No ViewBox but png converted correctly
var svg1 = await httpClient.GetStringAsync("https://img.vggcdn.net/svgv2/156660.svg?v=47");
ConvertSvgToPng(svg1, "./1-svg-no-viewbox-but-converted-correctly.png");
// #2 - No ViewBox but png converted incorrectly
var svg2 = await httpClient.GetStringAsync("https://img.vggcdn.net/svgv2/195035.svg?v=14");
ConvertSvgToPng(svg2, "./2-svg-no-viewbox-but-converted-incorrectly.png");
// #3 - ViewBox and png converted correctly
var svg3 = svg2.Replace("<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">", "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" viewBox=\"281 11 962 995\">");
ConvertSvgToPng(svg3, "./3-svg-viewbox-and-converted-correctly.png");
}
static void ConvertSvgToPng(string svg, string fileName)
{
var settings = new MagickReadSettings { Format = MagickFormat.Svg, BackgroundColor = MagickColors.Transparent };
using (var image = new MagickImage(Encoding.UTF8.GetBytes(svg), settings))
{
image.Write(new FileInfo(fileName), MagickFormat.Png32);
}
}
}
}System Configuration
- Magick.NET version: Magick.NET-Q16-AnyCPU 7.23.4
- Environment (Operating system, version and so on): Windows 10
- Additional information: