Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using Inkscape as delegate for SVG to PNG rendering in Magick.NET #1878

Unanswered
ctrebo asked this question in Help
Discussion options

Hello,
I’m wondering if it’s possible to configure Magick.NET to use Inkscape as the delegate for SVG to PNG rendering.

Context:

  • Magick.NET v14.7.0 in use
  • Environment: Windows Server but also tested on macOS (Apple Silicon, M1 chip)
  • Inkscape is already installed and accessible from the command line (inkscape ...)
  • ImageMagick itself is not yet installed on this server - only Magick.NET is currently in use
  • Any SVGs containing text tags with attributes lengthAdjust and textLength are not rendered as expected to Png meaning Inkscape is not used as delegate (converting the svgs with inkscape directly works as expected)

The goal would be to render SVG to PNG via Magick.NET, but have Inkscape handle the actual SVG parsing/conversion instead of the built in SVG renderer so newer SVG attributes like lengthAdjust and textLength are also supported.

So my question would be wheather it is even possible to use Inkscape as delegate for Magick.NET like it is in ImageMagick.

Thanks in advance for any guidance!

You must be logged in to vote

Replies: 4 comments 4 replies

Comment options

It should be used automatically when inkscape is available in the path.

You must be logged in to vote
0 replies
Comment options

Thank you for your answer @dlemstra!

In my case thats weird because then the SVGs should be rendered correctly. I now downloaded ImageMagick too on my mac and the results from ImageMagick and Magick.NET differ (lengthAdjust gets applied correctly with ImageMagick). The magick -verbose input.svg output.png command confirms inkscape is being used for ImageMagick. Is there a way to test the same for Magick.NET?

You must be logged in to vote
0 replies
Comment options

You can use the MagickNET.Log event and MagickNET.SetLogEvents to get more information. You might also need to set the Verbose property of the MagickReadSettings.

You must be logged in to vote
0 replies
Comment options

From the log it seems that Magick.NET is struggling to find the delegates.xml file from ImageMagick. It is searching e.g in "/usr/local/share/ImageMagick-7/delegates.xml" but not in "/opt/homebrew/etc/ImageMagick-7/delegates.xml" where my ImageMagick got installed using homebrew on mac.
Setting MagickNET.SetEnvironmentVariable("MAGICK_CONFIGURE_PATH", "/opt/homebrew/etc/ImageMagick-7/"); seems to make Magick.NET use the right delegates file just to now get a lot of inkscape errors like:

 'inkscape' '/var/folders/_g/7sh8bvrj7_51c0bj_mxhjh640000gn/T/magick-v4s3txaPBAVUReJeuLSKKWMXHSAK7wZi' '--export-filename=/var/folders/_g/7sh8bvrj7_51c0bj_mxhjh640000gn/T/magick-6iS5hujlLSWs5Cgd_a07NHxxVCbEldqe.png' '--export-dpi=96' '--export-background=rgb(0%,0%,0%)' '--export-background-opacity=0'
/var/folders/_g/7sh8bvrj7_51c0bj_mxhjh640000gn/T/magick-v4s3txaPBAVUReJeuLSKKWMXHSAK7wZi:1: parser error : Growing input buffer

and (translating from German)

** (org.inkscape.Inkscape:63279): WARNING **: 07:19:22.496: Could not recognise file format. Trying to open the file as SVG-file also failed.
/var/folders/_g/7sh8bvrj7_51c0bj_mxhjh640000gn/T/magick-v4s3txaPBAVUReJeuLSKKWMXHSAK7wZi:1: parser error : Growing input buffer

As reference, this is my simple Magick.NET code:

MagickNET.SetEnvironmentVariable("MAGICK_CONFIGURE_PATH", "/opt/homebrew/etc/ImageMagick-7/");
string svgData = @"
<svg width='400' height='100' xmlns='http://www.w3.org/2000/svg'>
 <rect width='100%' height='100%' fill='lightblue' />
 <text x='10' y='60'
 font-size='40'
 fill='darkblue'>
 Stretched Text dasfadsfadsfdafadfadfadsfad
 </text>
</svg>";
MagickNET.SetLogEvents(LogEventTypes.All);
MagickNET.Log += (sender, e) =>
{
 Console.WriteLine($"{e.Message}");
};
using var svgStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(svgData));
using var image = new MagickImage(svgStream, new MagickReadSettings
{
 Format = MagickFormat.Svg, 
 BackgroundColor = MagickColors.Transparent, // Optional: keep transparency
 Verbose = true
});
image.Write("output.png", MagickFormat.Png);

Do you know why this is happening or is this the wrong place to ask inkscape questons?
Thanks for all your help!

You must be logged in to vote
4 replies
Comment options

It looks like inkscape is failing. Is the command that is executed different from what is done on the command line with magick?

Comment options

Hmm, the commands being executed on my mac look pretty similar.
Its this one for the magick cli:
inkscape '/var/folders/.../magick-EThEO3LwO0YQA-hzzPSkZM1Ublba9iDr' \ --export-filename=/var/folders/_g/7sh8bvrj7_51c0bj_mxhjh640000gn/T/magick-E3RKS21u1svqcg_LJfIzk6SgxUKNCxpl.png \ --export-dpi=96 \ --export-background=rgb(100%,100%,100%) \ --export-background-opacity=1

and for magick.net its this one:
'inkscape' '/var/folders/.../magick-ppK2xjj-rEM8e6QpfkD06BStFvh6OYXv' '--export-filename=/var/folders/_g/7sh8bvrj7_51c0bj_mxhjh640000gn/T/magick-_Nt0dNZcu5SdvGILM8YZvgAxXckvP7A1.png' '--export-dpi=96' '--export-background=rgb(0%,0%,0%)' '--export-background-opacity=0'

and /var/folders/.../magick-ppK2xjj-rEM8e6QpfkD06BStFvh6OYXv:1: parser error : Growing input buffer written directly under it

Comment options

I don't know what is causing this. Maybe inkscape doesn't like that you use ' instead of "?

Comment options

Yeah really weird. Thanks for your help anyways!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /