Convert SVG to JPG in Windows produces blank JPG

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?".
kndti
Posts: 14
Joined: 2017-12-27T07:51:33-07:00
Authentication code: 1152

Convert SVG to JPG in Windows produces blank JPG

Post by kndti »

Hello all!

I have been searching around the message board for a couple of days and haven't found a topic that matches my situation exactly. What I'm trying to accomplish is a quick way to convert thousands of SVG files into JPG format via command line. ImageMagick seems to be able to fit the bill, however, I am running into a couple of situations where the SVG is converted and the result is a blank JPG. The vast majority of SVGs convert correctly. I also get the same result when converting to PNG format.

I have seen this issue addressed within a UNIX environment, but not Windows. Those other solutions seem to lean toward utilizing RSVG. Since I've installed the latest version of IM (v7.0.7-15 Q16 x64 2017-12-17), I already am using RSVG (v2.40.18).

Is there anything else you can suggest that I might try?

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

Re: Convert SVG to JPG in Windows produces blank JPG

Post by snibgo »

Perhaps the SVG is "empty", or contains code that RSVG can't process. What does Inkscape show? If Inkscape processes the SVG, then you can put Inkscape on your path and IM will use it instead of RSVG.

If you don't have Inkscape, you can link to an SVG, or paste it here if it is small between [ code ] and [ /code ], and I can test it.
snibgo's IM pages: im.snibgo.com
kndti
Posts: 14
Joined: 2017-12-27T07:51:33-07:00
Authentication code: 1152

Re: Convert SVG to JPG in Windows produces blank JPG

Post by kndti »

Here is one that works just fine:

Code: Select all

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" xml:space="preserve" width="1518.3364928909952606635071090" height="595"><g id="Layer_5"><line fill='none' stroke='#939598' stroke-width='0.5' x1='764' y1='28' x2='764' y2='564'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='874.3364928909952606635071090' y1='28' x2='874.3364928909952606635071090' y2='564'/><text transform='matrix(1 0 0 1 792 28)' font-family='TVNordCond' font-weight='' font-size='40'>Jan</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='973.6587677725118483412322275' y1='28' x2='973.6587677725118483412322275' y2='564'/><text transform='matrix(1 0 0 1 899 28)' font-family='TVNordCond' font-weight='' font-size='40'>Feb</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1084.3364928909952606635071090' y1='28' x2='1084.3364928909952606635071090' y2='564'/><text transform='matrix(1 0 0 1 1002 28)' font-family='TVNordCond' font-weight='' font-size='40'>Mar</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1190.7772511848341232227488152' y1='28' x2='1190.7772511848341232227488152' y2='564'/><text transform='matrix(1 0 0 1 1111 28)' font-family='TVNordCond' font-weight='' font-size='40'>Apr</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1301.3364928909952606635071090' y1='28' x2='1301.3364928909952606635071090' y2='564'/><text transform='matrix(1 0 0 1 1219 28)' font-family='TVNordCond' font-weight='' font-size='40'>May</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1407.7772511848341232227488152' y1='28' x2='1407.7772511848341232227488152' y2='564'/><text transform='matrix(1 0 0 1 1328 28)' font-family='TVNordCond' font-weight='' font-size='40'>Jun</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1518.3364928909952606635071090' y1='28' x2='1518.3364928909952606635071090' y2='564'/><text transform='matrix(1 0 0 1 1436 28)' font-family='TVNordCond' font-weight='' font-size='40'>Jul</text><text transform='matrix(1 0 0 1 149 106.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Analgesics - Anti-inflammatory</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='122' x2='1518' y2='122'/><text transform='matrix(1 0 0 1 162 169.5)' font-family='TVNordCond' font-weight='100' font-size='40'>IBUPROFEN 800 mg</text><rect x='764' y='134' fill='#0077AA' width='320' height='40'/><rect x='1045' y='134' fill='#0077AA' width='320' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='185' x2='1518' y2='185'/><text transform='matrix(1 0 0 1 149 232.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Anticonvulsants</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='248' x2='1518' y2='248'/><text transform='matrix(1 0 0 1 162 295.5)' font-family='TVNordCond' font-weight='100' font-size='40'>GABAPENTIN 300 mg</text><rect x='1045' y='260' fill='#0077AA' width='320' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='311' x2='1518' y2='311'/><text transform='matrix(1 0 0 1 149 358.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Antihypertensives</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='374' x2='1518' y2='374'/><text transform='matrix(1 0 0 1 162 421.5)' font-family='TVNordCond' font-weight='100' font-size='40'>LISINOPRIL 10 mg</text><rect x='764' y='386' fill='#0077AA' width='349' height='40'/><rect x='1045' y='386' fill='#0077AA' width='320' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='437' x2='1518' y2='437'/><text transform='matrix(1 0 0 1 149 484.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Ulcer Drugs</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='500' x2='1518' y2='500'/><text transform='matrix(1 0 0 1 162 547.5)' font-family='TVNordCond' font-weight='100' font-size='40'>OMEPRAZOLE 20 mg</text><rect x='764' y='512' fill='#0077AA' width='349' height='40'/><rect x='1045' y='512' fill='#0077AA' width='320' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='563' x2='1518' y2='563'/></g></svg>
This one converts to blank:

Code: Select all

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" xml:space="preserve" width="1518.3364928909952606635071090" height="658"><g id="Layer_5"><line fill='none' stroke='#939598' stroke-width='0.5' x1='764' y1='28' x2='764' y2='627'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='874.3364928909952606635071090' y1='28' x2='874.3364928909952606635071090' y2='627'/><text transform='matrix(1 0 0 1 792 28)' font-family='TVNordCond' font-weight='' font-size='40'>Jan</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='973.6587677725118483412322275' y1='28' x2='973.6587677725118483412322275' y2='627'/><text transform='matrix(1 0 0 1 899 28)' font-family='TVNordCond' font-weight='' font-size='40'>Feb</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1084.3364928909952606635071090' y1='28' x2='1084.3364928909952606635071090' y2='627'/><text transform='matrix(1 0 0 1 1002 28)' font-family='TVNordCond' font-weight='' font-size='40'>Mar</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1190.7772511848341232227488152' y1='28' x2='1190.7772511848341232227488152' y2='627'/><text transform='matrix(1 0 0 1 1111 28)' font-family='TVNordCond' font-weight='' font-size='40'>Apr</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1301.3364928909952606635071090' y1='28' x2='1301.3364928909952606635071090' y2='627'/><text transform='matrix(1 0 0 1 1219 28)' font-family='TVNordCond' font-weight='' font-size='40'>May</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1407.7772511848341232227488152' y1='28' x2='1407.7772511848341232227488152' y2='627'/><text transform='matrix(1 0 0 1 1328 28)' font-family='TVNordCond' font-weight='' font-size='40'>Jun</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='1518.3364928909952606635071090' y1='28' x2='1518.3364928909952606635071090' y2='627'/><text transform='matrix(1 0 0 1 1436 28)' font-family='TVNordCond' font-weight='' font-size='40'>Jul</text><text transform='matrix(1 0 0 1 149 106.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Analgesics - Anti-inflammatory</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='122' x2='1518' y2='122'/><text transform='matrix(1 0 0 1 162 169.5)' font-family='TVNordCond' font-weight='100' font-size='40'>DICLOFENAC SODIUM DR 75 mg</text><rect x='764' y='134' fill='#0077AA' width='320' height='40'/><rect x='864' y='134' fill='#0077AA' width='320' height='40'/><rect x='1184' y='134' fill='#0077AA' width='320' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='185' x2='1518' y2='185'/><text transform='matrix(1 0 0 1 149 232.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Antihypertensives</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='248' x2='1518' y2='248'/><text transform='matrix(1 0 0 1 162 295.5)' font-family='TVNordCond' font-weight='100' font-size='40'>LISINOPRIL 20 mg</text><rect x='764' y='260' fill='#0077AA' width='320' height='40'/><rect x='839' y='260' fill='#0077AA' width='320' height='40'/><rect x='1159' y='260' fill='#0077AA' width='320' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='311' x2='1518' y2='311'/><text transform='matrix(1 0 0 1 149 358.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Beta Blockers</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='374' x2='1518' y2='374'/><text transform='matrix(1 0 0 1 162 421.5)' font-family='TVNordCond' font-weight='100' font-size='40'>ATENOLOL 50 mg</text><rect x='764' y='386' fill='#0077AA' width='324' height='40'/><rect x='992' y='386' fill='#0077AA' width='320' height='40'/><rect x='1252' y='386' fill='#0077AA' width='266' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='437' x2='1518' y2='437'/><text transform='matrix(1 0 0 1 149 484.5)' font-family='TVNordCond' font-weight='bolder' font-size='40'>Minerals & Electrolytes</text><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='500' x2='1518' y2='500'/><text transform='matrix(1 0 0 1 162 547.5)' font-family='TVNordCond' font-weight='100' font-size='40'>KLOR-CON 10 10 meq</text><rect x='1305' y='512' fill='#0077AA' width='213' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='563' x2='1518' y2='563'/><text transform='matrix(1 0 0 1 162 610.5)' font-family='TVNordCond' font-weight='100' font-size='40'>POTASSIUM CHLORIDE ER 10 meq</text><rect x='1063' y='575' fill='#0077AA' width='107' height='40'/><rect x='1230' y='575' fill='#0077AA' width='107' height='40'/><line fill='none' stroke='#939598' stroke-width='0.5' x1='149' y1='626' x2='1518' y2='626'/></g></svg>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to JPG in Windows produces blank JPG

Post by fmw42 »

When I create your svg file (and display in Mac PREVIEW), it shows an error message at the top of the file as follows:

Code: Select all

This page contains the following errors:

error on line 1 at column 4035: xmlParseEntityRef: no name
kndti
Posts: 14
Joined: 2017-12-27T07:51:33-07:00
Authentication code: 1152

Re: Convert SVG to JPG in Windows produces blank JPG

Post by kndti »

For both, or just the one that isn't converting?

When I look at the problem file in IE, it displays correctly as far as I can tell. When I open it in IMDisplay, it shows blank.

Is there a way for IM to report errors in files during the conversion? If I convert this via command line, it doesn't provide any feedback and acts as if the conversion happened correctly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to JPG in Windows produces blank JPG

Post by fmw42 »

For the bad one. I did not check the good one.

In IM add -debug all to your command. But that is not easy to interpret. The basic issue is the renderer that ImageMagick uses is objecting. I used RSVG delegate. Try running RSVG standalone and see what error you get. Or try Inkscape, which may work better.

You can also add -verbose to see what RSVG or Inkscape is doing:

Code: Select all

convert -verbose test.svg test.png
'inkscape' '/tmp/magick-55310Mpo7s0VjTN6v' --export-png='/tmp/magick-55310enMZKCfcOaRJ' --export-dpi='96,96' --export-background='rgb(100%,100%,100%)' --export-background-opacity='1' > '/tmp/magick-55310waI1puMUomvd' 2>&1
test.svg SVG 1518x658 1518x658+0+0 16-bit sRGB 4793B 0.040u 0:00.039
test.svg=>test.png SVG 1518x658 1518x658+0+0 8-bit sRGB 1c 825B 0.030u 0:00.019
kndti
Posts: 14
Joined: 2017-12-27T07:51:33-07:00
Authentication code: 1152

Re: Convert SVG to JPG in Windows produces blank JPG

Post by kndti »

Well.. I installed Inkscape, and it appears to convert the problem SVG into a valid PNG (while spitting out that same error that you quoted). But Magick doesn't appear to be utilizing Inkscape when it runs. When I look at -list format, it still references RSVG and when I use the -verbose, I get this:

P:\Wellpoint\DataFiles\data_20171017_MHN\graphs\a_png\67901530.svg SVG 1518x658
1518x658+0+0 16-bit sRGB 4793B 0.062u 0:00.079
P:\Wellpoint\DataFiles\data_20171017_MHN\graphs\a_png\67901530.svg=>P:\Wellpoint
\DataFiles\data_20171017_MHN\graphs\b_jpg\67901530.jpg SVG 1518x658 1518x658+0+0
16-bit Bilevel Gray 4103B 0.078u 0:00.093

And the resulting JPG is still blank. What do I need to do to make Magick utilize Inkscape when converting these SVGs into JPGs?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to JPG in Windows produces blank JPG

Post by fmw42 »

ImageMagick is supposed to use Inkscape if it exist on your system and IM can find it even if you have RSVG installed.

Try using Inkscape directly.
kndti
Posts: 14
Joined: 2017-12-27T07:51:33-07:00
Authentication code: 1152

Re: Convert SVG to JPG in Windows produces blank JPG

Post by kndti »

It's supposed to, yes, but does not appear to be doing that for me. What am I missing?

I have used Inkscape directly, but it does not convert SVG directly to JPG. Speed of conversion is vital to me, and if I have to convert from SVG to PNG, then from PNG to JPG, I will be doubling my processing time. If that is what I must do, so be it, but I should be able to do this all in one command line execution. Or am I misinterpreting what's happening here?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to JPG in Windows produces blank JPG

Post by fmw42 »

Did Inkscape by itself work to convert to PNG on the bad one? But ImageMagick is failing?

What do you get from

Code: Select all

magick -list format
for the line starting with SVG? Does it say RSVG or Inkscape?

I am not using Inkspace and mine says:

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.40.18)

I have no experience with Inkscape.

Perhaps one of the other Inkscape users can help you check if your ImageMagick is actually using Inkscape?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to JPG in Windows produces blank JPG

Post by fmw42 »

The page at http://www.imagemagick.org/script/formats.php says:

SVG RW Scalable Vector Graphics ImageMagick utilizes inkscape if its in your execution path otherwise RSVG. If neither are available, ImageMagick reverts to its internal SVG renderer. The default resolution is 96 DPI. Use -size command line option to specify the maximum width and height.

Is Inkscape in your execution PATH? Did you install before or after ImageMagick?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert SVG to JPG in Windows produces blank JPG

Post by snibgo »

kndti wrote:What do I need to do to make Magick utilize Inkscape when converting these SVGs into JPGs?
What happens when you type "inkscape" on the command line? It should start inkscape. If it doesn't, you need to change you system path to include the Inkscape directory.
snibgo's IM pages: im.snibgo.com
kndti
Posts: 14
Joined: 2017-12-27T07:51:33-07:00
Authentication code: 1152

Re: Convert SVG to JPG in Windows produces blank JPG

Post by kndti »

Inkscape does convert the problem file from SVG to PNG successfully.

When I run Magick -list format, it gives me the same information that you have (RSVG 2.40.18)

If I am in the Inkscape directory, running "Inkscape" at the command line opens the Inkscape program.

Is there a config file for Magick somewhere that I need to update in addition to having installed Inkscape?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert SVG to JPG in Windows produces blank JPG

Post by snibgo »

kndti wrote:If I am in the Inkscape directory, running "Inkscape" at the command line opens the Inkscape program.
It needs to work when you are in any directory.

In effect, IM runs the command "inkscape", from whatever directory IM is run from. If the "inkscape" command doesn't work for you, then it won't work for IM.
snibgo's IM pages: im.snibgo.com
kndti
Posts: 14
Joined: 2017-12-27T07:51:33-07:00
Authentication code: 1152

Re: Convert SVG to JPG in Windows produces blank JPG

Post by kndti »

I added the Inkscape directory to my path system variable, and now I can execute Inkscape from any directory.

Magick still reports using RSVG, and when I convert to JPG, it's still blank.
Post Reply