Converting png to svg: Imagemagick can't read the resulting file
Posted: 2019-09-26T17:49:46-07:00
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.
As an example, I'll use XKCD page 109. I saved the image as xkcd.png.
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
tells me that the image is entirely white:
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:
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.
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
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
Code: Select all
magick identify -verbose xkcd.svg
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
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
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.