Trouble converting svg with base64 images to png with rsvg

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
pneves
Posts: 7
Joined: 2018-05-28T12:32:17-07:00
Authentication code: 1152

Trouble converting svg with base64 images to png with rsvg

Post by pneves »

Hello, I'm having a bit of a problem with ImageMagick. I was originally having trouble getting fonts to appear on my png images converted from svg. After many days I finally found on a forum somewhere environment variable that needed to be set to get fonts working in my program. However, in the process I managed to break the rendering of base64 encoded images that are embeded in my svg file.

My original install was on ubuntu 18.04 with the base packages. However, I couldn't get the fonts working so I compiled the latest version of image magick and along with the latest version of librsvg. And provided the export PANGOCAIRO_BACKEND=fc environment variable to the command line to get the fonts working. And everything is working except for one thing. My base64 images are getting mangled. Meaning I that I think the base64 image encoding is getting cut off or something because it doesn't complete the rendering of the image. I was wondering if someone knows of an environment setting, ImageMagick setting, compile configure parameter, or something to get the base64 encoded images to render properly. These issues have already taken me more then a week of searching online searching through various sites, posts to irc which have gone unanswered and forums and I can't find a solution to my problem.

Any assistance would be a great help thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble converting svg with base64 images to png with rsvg

Post by fmw42 »

Always best to provide your ImageMagick version and platform when asking questions. Also the version of librsvg. Have you tried using Inkscape?
pneves
Posts: 7
Joined: 2018-05-28T12:32:17-07:00
Authentication code: 1152

Re: Trouble converting svg with base64 images to png with rsvg

Post by pneves »

The original version of imagemagick was 6.9.7.4 the version of ImageMagick I'm currently using is 7.0.7-35 and the version of librsvg-2.42.4.

I do have inkscape installed as well. Not sure however, if its using it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trouble converting svg with base64 images to png with rsvg

Post by snibgo »

I suggest you supply a SVG that shows the problem, and the exact command you used to convert it. When you run that command with "-verbose", what is the text output? That should tell us what delegate is being used.
snibgo's IM pages: im.snibgo.com
pneves
Posts: 7
Joined: 2018-05-28T12:32:17-07:00
Authentication code: 1152

Re: Trouble converting svg with base64 images to png with rsvg

Post by pneves »

I'm actually using php-imagick. But the issue is coming from ImageMagick itself. I'm grabbing the contents of the svg converting it to png. THen sending it out as a response through laravel. However, I don't think its this code thats causing the problem. The images used to render properly before I tried installing to fix the font issue. Now that the font issue is working I'm now not able to get the base64 encoding. I'm just wondering if there is some sort of compile flag that I need to set to increase the size of the base64 encoded url that ImageMagick will accept. I'm pretty sure this is some sort of compile issue that I introduced when I tried to fix my font issue. The images do show up. They just aren't fully rendered. So I think the url might be getting cut off or something. The images that I'm rendering are also png files as well.

$contents = file_get_contents($input_file . '.svg');

$image_render = new \Imagick();

$image_render->readimageblob($contents);

$image_render->setImageFormat('png24');

return Response::create($image_render->getImageBlob(), 200, ['Content-type' => $content_type]);
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trouble converting svg with base64 images to png with rsvg

Post by snibgo »

So you have multiple layers of software, with IMagick then ImageMagick then some SVG renderer delegate at the bottom.

Some upper layer may limit the memory that can be allocated by a lower layer.

To eliminate upper levels, I suggest you try at the command level. For example:

Code: Select all

magick in.svg out.png
Does that work? If it does, then your SVG file is okay and IM can render it. If it doesn't work, see if Inkscape can render it.

If IM and Inkscape both render it but it fails at higher levels, what does the output look like, compared to a successful rendering?
snibgo's IM pages: im.snibgo.com
pneves
Posts: 7
Joined: 2018-05-28T12:32:17-07:00
Authentication code: 1152

Re: Trouble converting svg with base64 images to png with rsvg

Post by pneves »

Is there a way to set the memory restrictions in ImageMagick? or in librsvg or in Inkscape?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trouble converting svg with base64 images to png with rsvg

Post by snibgo »

Memory limits can be set within ImageMagick by the "-limit" command or by policy.xml. But your situation may have limits imposed.
snibgo's IM pages: im.snibgo.com
pneves
Posts: 7
Joined: 2018-05-28T12:32:17-07:00
Authentication code: 1152

Re: Trouble converting svg with base64 images to png with rsvg

Post by pneves »

Here is what is going on.
https://www.dropbox.com/s/5sa0cxfnfryi1 ... M.png?dl=0

https://www.dropbox.com/s/z853ebbhblomj ... M.png?dl=0




The logo's on these two images should be identical. The font maybe not because the images are generated in two different ways. But the logo itself should be identical. It's actually the same image. One was generated by fabric.js and the other one is generated by Imagemagic.

In this the svg output of fabric.js is put through imagemagick to generate png file.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble converting svg with base64 images to png with rsvg

Post by fmw42 »

Looks to me like a case of font substitution for a font that is not recognized. But I am not an SVG expert. If one of your fonts is not public, that can happen.
pneves
Posts: 7
Joined: 2018-05-28T12:32:17-07:00
Authentication code: 1152

Re: Trouble converting svg with base64 images to png with rsvg

Post by pneves »

I know whats causing hte font issue. Its the image thats the problem the N. if you look at the N in that logo its not completely filled in on the image magick generated image. That happens to be an embeded image that has been converted to a base64 string.
pneves
Posts: 7
Joined: 2018-05-28T12:32:17-07:00
Authentication code: 1152

Re: Trouble converting svg with base64 images to png with rsvg

Post by pneves »

Anyone have any idea what might be causing this issue with my images where it's not rendering an embedded image?
Post Reply