Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

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
Gim6626
Posts: 4
Joined: 2019-01-22T03:25:44-07:00
Authentication code: 1152

Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by Gim6626 »

I've upgraded ImageMagick with my Ubuntu from 8:6.8.9.9-7ubuntu5.13 and 16.04 to 8:6.9.10.8+dfsg-1ubuntu2 and 18.10 and faced strange issue. Simple test SVG code now fails to convert to PNG and shows only black rectangle.

Here is SVG code:

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="500" height="300" xmlns="http://www.w3.org/2000/svg">
  <title>Singleton Pattern</title>
  <defs>
    <style type="text/css">
      <![CDATA[
        g{
          stroke       : #000;
        }
        rect, path, circle{
          fill         : #fff;
          fill-opacity : 0;
        }
        rect{
          stroke-width : 6;
        }
        path, circle, line{
          stroke-width : 2;
        }
        text{
          fill         : #000;
          stroke-width : 0;
          font-family  : sans-serif;
          font-size    : 25px;
        }
        text.name{
          fill         : #000;
          stroke-width : 0;
          font-weight  : bold;
          text-anchor  : middle;
          font-family  : sans-serif;
          font-size    : 25px;
        }
        text.visibility{
          fill         : #000;
          stroke-width : 0;
          font-size    : 28px;
          font-family  : monospace;
          font-weight  : bold;
          text-anchor  : middle;
        }
      ]]>
    </style>
  </defs>
  <g transform="translate(50,50)">
    <rect width="400" height="200" />
    <line x1="0" x2="400" y1="60"  y2="60" />
    <line x1="0" x2="400" y1="110" y2="110" />
    <text x="200" y="45"  class="name">Singleton</text>
    <text x="30"  y="95"  class="visibility">-</text>
    <text x="60"  y="95">singleton : Singleton</text>
    <line x1="30" x2="370" y1="100" y2="100" />
    <text x="30"  y="145" class="visibility">-</text>
    <text x="60"  y="145">Singleton()</text>
    <text x="30"  y="180" class="visibility">+</text>
    <text x="60"  y="180">getInstance() : Singleton</text>
    <line x1="30" x2="370" y1="185" y2="185" />
  </g>
</svg>
I use simple command for conversion:

Code: Select all

convert foo.svg foo.png
Here is PNG created from it on 8:6.8.9.9-7ubuntu5.13 (Ubuntu 16.04):
Image

And here is PNG from newer 8:6.9.10.8+dfsg-1ubuntu2 (Ubuntu 18.10):
Image

Online tools like https://svgtopng.com work perfectly, it makes me think that SVG code is correct. Also my SVG example is taken from https://en.wikipedia.org/wiki/Singleton ... iagram.svg and are shown in browser correctly, which also make me think that problem is not in SVG.

Could anybody help to make newer version work? Or maybe there is some bug in it?
Last edited by Gim6626 on 2019-01-22T20:40:05-07:00, edited 3 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by fmw42 »

Your images cannot be accessed. Please fix your links.
Gim6626
Posts: 4
Joined: 2019-01-22T03:25:44-07:00
Authentication code: 1152

Re: Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by Gim6626 »

fmw42 wrote: 2019-01-22T13:23:51-07:00 Your images cannot be accessed. Please fix your links.
Sorry. Fixed.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by snibgo »

What delegate renders the SVG? I expect Inkscape should be okay, but MSVG almost certainly can't process the embedded CSS.
snibgo's IM pages: im.snibgo.com
Gim6626
Posts: 4
Joined: 2019-01-22T03:25:44-07:00
Authentication code: 1152

Re: Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by Gim6626 »

snibgo wrote: 2019-01-22T20:51:46-07:00 What delegate renders the SCG?
Sorry, but I don't undestand your question. Could you explain it?
snibgo wrote: 2019-01-22T20:51:46-07:00 I expect Inkscape should be okay, but MSVG almost certainly can't process the embedded CSS.
Inkscape shows file correctly.
Gim6626
Posts: 4
Joined: 2019-01-22T03:25:44-07:00
Authentication code: 1152

Re: Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by Gim6626 »

Could not reproduce this bug anymore. Don't understand what happened.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by fmw42 »

snibgo wrote: ↑Tue Jan 22, 2019 7:51 pm
What delegate renders the SCG?
Sorry, but I don't undestand your question. Could you explain it?
SVG files are vector files and Imagemagick uses some other tool to convert them to raster images.

He is asking what renderer you are using to convert the vector SVG file into a raster image? Imagemagick can use Inkscape, the RSVG delegate and the internal Imagemagick MSVG/XML renderer, in order of decreasing quality for the result. If you have not installed Inkscape, it will RSVG if you installed that. Otherwise, it will use MSVG/XML.

You can find out which of the latter, by

convert -list format

and look at the end of the line for SVG. It will say RSVG or XML. But if Inkscape is installed it will not show that.

Alternately, just add -verbose to your command line and it will show the renderer and the command used by the renderer.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Only black rectangle on PNG converted from simple SVG code in newer version of ImageMagick

Post by fmw42 »

Gim6626 wrote: 2019-01-23T01:20:48-07:00 Could not reproduce this bug anymore. Don't understand what happened.
Once Inkscape is installed and it worked once, it will work again. So it is likely that you are now using Inkscape to render all SVG files.
Post Reply