Converting png to svg: Imagemagick can't read the resulting file

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
bgb16999
Posts: 2
Joined: 2019-09-25T18:31:09-07:00
Authentication code: 1152

Converting png to svg: Imagemagick can't read the resulting file

Post by bgb16999 »

On the latest version of Imagemagick, I am having an issue with converting between raster and vector graphics. When I convert a png to an svg, Imagemagick seems to be able to convert it correctly. However, subsequent imagemagick operations on the resulting svg file do not work correctly.

Code: Select all

 magick identify -version
Version: ImageMagick 7.0.8-66 Q16 x64 2019-09-22 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenCL OpenMP(2.0)
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr lzma openexr pangocairo png ps raw rsvg tiff webp xml zlib
As an example, I'll use XKCD page 109. I saved the image as xkcd.png.

Code: Select all

 magick identify xkcd.png
xkcd.png PNG 450x467 450x467+0+0 8-bit sRGB 46797B 0.000u 0:00.026

Code: Select all

 magick convert xkcd.png xkcd.svg 
The conversion works. I can open xkcd.svg in a browser and it displays an image that looks the same as the original png. However, when I try to run further commands on it, I run into a problem. Running

Code: Select all

magick identify -verbose xkcd.svg
tells me that the image is entirely white:

Code: Select all

Image: xkcd.svg
  Format: SVG (Scalable Vector Graphics)
  Mime type: image/svg+xml
  Class: DirectClass
  Geometry: 450x467+0+0
  Resolution: 96x96
  Print size: 4.6875x4.86458
  Units: Undefined
  Colorspace: sRGB
  Type: Bilevel
  Base type: Undefined
  Endianess: Undefined
  Depth: 16/1-bit
  Channel depth:
    Red: 1-bit
    Green: 1-bit
    Blue: 1-bit
    Alpha: 1-bit
  Channel statistics:
    Pixels: 210150
    Red:
      min: 65535  (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: 0 (0)
      kurtosis: 1.6384e+052
      skewness: 9.375e+035
      entropy: 0
    Green:
      min: 65535  (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: 0 (0)
      kurtosis: 1.6384e+052
      skewness: 9.375e+035
      entropy: 0
    Blue:
      min: 65535  (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: 0 (0)
      kurtosis: 1.6384e+052
      skewness: 9.375e+035
      entropy: 0
    Alpha:
      min: 65535  (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: 0 (0)
      kurtosis: 1.6384e+052
      skewness: 9.375e+035
      entropy: 0
  Image statistics:
    Overall:
      min: 65535  (1)
      max: 65535 (1)
      mean: 65535 (1)
      standard deviation: 0 (0)
      kurtosis: 1.6384e+052
      skewness: 9.375e+035
      entropy: 0
  Colors: 1
  Histogram:
    210150: (65535,65535,65535,65535) #FFFFFFFFFFFFFFFF white
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 450x467+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    date:create: 2019-09-27T00:11:25+00:00
    date:modify: 2019-09-27T00:11:25+00:00
    signature: d3a6c741582d09fdee89fdbe6081860b0d06baeef191d2a2f9c641747038c9ab
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 81392B
  Number pixels: 210150
  Pixels per second: 15.603MP
  User time: 0.016u
  Elapsed time: 0:01.013
  Version: ImageMagick 7.0.8-66 Q16 x64 2019-09-22 http://www.imagemagick.org
Even though the whole image is contained in the svg file, and can be read by a browser, imagemagick can't read it correctly.
Converting from svg back to png yields a similar problem:

Code: Select all

magick convert xkcd.svg xkcd2.png

Code: Select all

 magick identify xkcd2.png
xkcd2.png PNG 450x467 450x467+0+0 8-bit Gray 2c 376B 0.000u 0:00.000
The resulting image is all white.


For some bizarre reason, these issues do not occur for images that start out as SVGs: If I download an svg file from the internet, or create one with Inkscape, Imagemagick is able to identify it and convert it to a png correctly. This issue only occurs for images which I have converted to svg using imagemagick.

I don't know whether this is a bug in imagemagick or whether it just means I don't understand something about what I am doing, so I would appreciate any light you can shed on this situation.

Thanks.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting png to svg: Imagemagick can't read the resulting file

Post by snibgo »

If you post a link to the generated SVG, someone might figure out what is wrong with it.
snibgo's IM pages: im.snibgo.com
bgb16999
Posts: 2
Joined: 2019-09-25T18:31:09-07:00
Authentication code: 1152

Re: Converting png to svg: Imagemagick can't read the resulting file

Post by bgb16999 »

Here's a pastebin link to the svg as a text file.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting png to svg: Imagemagick can't read the resulting file

Post by snibgo »

In the SVG file, which Inkscape shows as exactly white, the embedded raster image starts with:

Code: Select all

href="data:image/png;base64,iVBO ...
If we change it to...

Code: Select all

xlink:href="data:image/png;base64,iVBO ...
... then Inkscape correctly shows the embedded image.

I assume this is an IM bug, so I'll move this to the bugs forum.
snibgo's IM pages: im.snibgo.com
Post Reply