convert bmp to svg

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?".
edepperson
Posts: 8
Joined: 2014-05-02T07:29:51-07:00
Authentication code: 6789

convert bmp to svg

Post by edepperson »

I'm trying to convert a bmp (I've also tried jpg) to an svg file. If I run convert without auto trace, I get a huge file. But running convert with autotrace gets me an error. With the error below, I included the path to autotrace in my environment. But I've also tried editing the delegate.xml file. Same error both times.

here is the bat file I run: "C:\Program Files\ImageMagick-6.8.9-Q16\convert.exe" autotrace:EGBtraining_001.bmp -scene 1 EGBtraining_001.svg

Here is a copy of the error I'm getting:
C:\MediaConvPath\4\13>"C:\Program Files\ImageMagick-6.8.9-Q16\convert.exe" autotrace:EGBtraining_001.bmp -scene 1 EGBtraining_001.svg
fatal: Unsupported input format.
convert.exe: Delegate failed `autotrace -output-format svg -output-file "%o" "%i"' @ error/delegate.c/InvokeDelegate/1124.
convert.exe: unable to open image `C:/Temp/Email/magick-44286_NVswUOlOZB': No such file or directory @ error/blob.c/OpenBlob/2647.
convert.exe: unable to open module file `C:\Program Files\ImageMagick-6.8.9-Q16\modules\coders\IM_MOD_RL_AUTOTRACE_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/672.
convert.exe: unable to open file `C:/Temp/Email/magick-44286_NVswUOlOZB': No such file or directory @ error/constitute.c/ReadImage/540.
convert.exe: no images defined `EGBtraining_001.svg' @ error/convert.c/ConvertImageCommand/3161.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert bmp to svg

Post by snibgo »

I don't use autotrace (I use potrace), so I probably can't help. It looks as if IM is trying to run autotrace but failing. What does "-verbose" show? What happens when you run autotrace directly?
snibgo's IM pages: im.snibgo.com
edepperson
Posts: 8
Joined: 2014-05-02T07:29:51-07:00
Authentication code: 6789

Re: convert bmp to svg

Post by edepperson »

Here is the verbose output

C:\Users\Dixon\Desktop\_13 - Copy>"C:\Program Files\ImageMagick-6.8.9-Q16\convert.exe" -verbose autotrace:EGBtraining_001.bmp -scene 1 EGBtraining_001.svg
autotrace -output-format svg -output-file "C:/Temp/Email/magick-8696_3WgRnGGegj4" "C:/Temp/Email/magick-8696fTNxRl3HWaIo"
fatal: Unsupported input format.
convert.exe: Delegate failed `autotrace -output-format svg -output-file "%o" "%i"' @ error/delegate.c/InvokeDelegate/1124.
convert.exe: unable to open image `C:/Temp/Email/magick-8696LQWXjWx22ICi': No such file or directory @ error/blob.c/OpenBlob/2647.
convert.exe: unable to open module file `C:\Program Files\ImageMagick-6.8.9-Q16\modules\coders\IM_MOD_RL_AUTOTRACE_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/672.
convert.exe: unable to open file `C:/Temp/Email/magick-8696LQWXjWx22ICi': No such file or directory @ error/constitute.c/ReadImage/540.
convert.exe: no images defined `EGBtraining_001.svg' @ error/convert.c/ConvertImageCommand/3161.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert bmp to svg

Post by snibgo »

edepperson wrote:autotrace -output-format svg -output-file "C:/Temp/Email/magick-8696_3WgRnGGegj4" "C:/Temp/Email/magick-8696fTNxRl3HWaIo"

fatal: Unsupported input format.
It seems that autotrace complains about "Unsupported input format".

Very old and minimal documentation (http://autotrace.sourceforge.net/ ) says "Inputformats BMP, TGA, PNM, PPM, PGM, PBM and those supported by ImageMagick." I suspect IM is creating a PNG file for autotrace, and this isn't a native file format for autotrace, and it isn't calling IM correctly to translate it back.

What happens when you run autotrace directly on your BMP file?

What is your delegates.xml entry for autotrace?
snibgo's IM pages: im.snibgo.com
edepperson
Posts: 8
Joined: 2014-05-02T07:29:51-07:00
Authentication code: 6789

Re: convert bmp to svg

Post by edepperson »

when I run autotrace.exe on the bmp file, I get the error below. (maybe my commnd line is wrong)

C:\WebSites\CBT\CBT\Media\4\13\Slides>C:\ProgramDownloads\Autotrace\autotrace.exe -input-format=bmp -output-format=svg -output-file=EGBTraining_001.svg EGBtraining_001.bmp
Error reading BMP file header

here is the delegate in IM
<delegate decode="autotrace" stealth="True" command="autotrace -output-format svg -output-file "%o" "%i""/>

delegate in autotrace

<?xml version="1.0"?>
<delegatemap>
<delegate decode="browse" restrain="True" spawn="True" command='cmd /C start http://www.imagemagick.org/ImageMagick/' />
<delegate decode="bzip" restrain="True" command='|bzip2 -cd "%i"' />
<delegate decode="cgm" command='ralcgm -d ps "%i" "%o" %u\nconvert -concatenate "%o"*.ps "%o"' />
<delegate decode="compress" restrain="True" command='|uncompress -c "%i"' />
<delegate decode="dot" command='dot -Tps "%i" -o "%o"' />
<delegate decode="dvi" command='dvips -q -o "%o" "%i"' />
<delegate decode="edit" restrain="True" command='notepad "%o"' />
<delegate decode="emf" command='wmftopng "%i" "%o"' />
<delegate decode="eps" encode="pdf" mode="bi" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pdfwrite -sOutputFile=%o -- "%i" -c quit' />
<delegate decode="eps" encode="ps" mode="bi" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pswrite -sOutputFile=%o -- "%i" -c quit' />
<delegate decode="fig" command='/usr/X11R6/bin/fig2dev -L ps "%i" "%o"' />
<delegate decode="gplt" command='/bin/echo "set size 1.25,0.62\nset terminal postscript portrait color solid; set output "%o"; load "%i"" > %u;gnuplot %u' />
<delegate decode="gs-color" restrain="True" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pnmraw -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -g%s -r%s %s -sOutputFile=%s -- "%s" -c quit' />
<delegate decode="gs-mono" restrain="True" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pbmraw -dTextAlphaBits=%u -dGraphicsAlphaBits=%u -g%s -r%s %s -sOutputFile=%s -- "%s" -c quit' />
<delegate decode="hpgl" command='hp2xx -q -m eps -f `basename "%o"` "%i"\nmv `basename "%o"` "%o' />
<delegate decode="htm" command='html2ps -U -o "%o" "%i"' />
<delegate decode="html" command='html2ps -U -o "%o" "%i"' />
<delegate decode="ilbm" command='ilbmtoppm "%i" > "%o"' />
<delegate decode="m2v" command='mpeg2decode -q -b "%i" -f -r -o3 "%o%%05d"\n/usr/local/bin/convert -concatenate "%o*.ppm" "%o"' />
<delegate decode="man" command='groff -man -Tps "%i" > "%o"' />
<delegate decode="mpeg" command='mpeg2decode -q -b "%i" -f -r -o3 "%o%%05d"\n/usr/local/bin/convert -concatenate "%o*.ppm" "%o"' />
<delegate decode="mpg" command='mpeg2decode -q -b "%i" -f -r -o3 "%o%%05d"\n/usr/local/bin/convert -concatenate "%o*.ppm" "%o"' />
<delegate decode="pdf" encode="eps" mode="bi" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=epswrite -sOutputFile=%o -- "%i" -c quit' />
<delegate decode="pdf" encode="ps" mode="bi" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pswrite -sOutputFile=%o -- "%i" -c quit' />
<delegate decode="pgp" command='pgpv -fq "%i"' />
<delegate decode="pnm" encode="ilbm" mode="encode" command='ppmtoilbm -24if "%i" > "%o"' />
<delegate decode="bmp" encode="launch" mode="encode" command='c:"\Program Files\Accessories\mspaint.exe" "%i"' />
<delegate decode="bmp" encode="win" mode="encode" command='c:"\Program Files\Accessories\mspaint.exe" "%i"' />
<delegate decode="pov" command='povray "+i"%i"" +o"%o" +fn%q +w%w +h%h +a -q9 -kfi"%s" -kff"%n"\nconvert -concatenate "%o*.png" "%o"' />
<delegate decode="ps" encode="eps" mode="bi" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=epswrite -sOutputFile=%o -- "%i" -c quit' />
<delegate decode="ps" encode="pdf" mode="bi" command='gswin32c -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=pdfwrite -sOutputFile=%o -- "%i" -c quit' />
<delegate decode="pcl" encode="print" mode="encode" command='print "%i"' />
<delegate decode="rad" command='ra_ppm -g 1.0 "%i" "%o"' />
<delegate decode="rgba" encode="rle" mode="encode" command='mogrify -flip -size %wx%h "rgba:%i"\nrawtorle -w %w -h %h -n 4 -o "%o" "%i"' />
<delegate decode="scan" command='scanimage -d "%i" > "%o"' />
<delegate decode="shtml" command='html2ps -U -o "%o" "%i"' />
<delegate decode="txt" encode="ps" mode="bi" command='enscript -o "%o" "%i"' />
<delegate decode="wmf" command='wmftopng "%i" "%o"' />
<delegate decode="xcf" command='xcftopnm "%i" > "%o"' />
<delegate decode="yuv" encode="m2v" mode="encode" command='mpeg2encode %u "%o"\n/usr/local/bin/convert -concatenate "%i*.yuv" %u' />
<delegate decode="yuv" encode="mpeg" mode="encode" command='mpeg2encode %u "%o"\n/usr/local/bin/convert -concatenate "%i*.yuv" %u' />
<delegate decode="yuv" encode="mpg" mode="encode" command='mpeg2encode %u "%o"\n/usr/local/bin/convert -concatenate "%i*.yuv" %u' />
<delegate decode="zip" restrain="True" command='|gzip -cdfq "%i"' />
<delegate encode="bzip" restrain="True" command='|bzip2 -f > "%o"' />
<delegate encode="compress" restrain="True" command='|compress -c > "%o"' />
<delegate encode="show" restrain="True" spawn="True" command='display -immutable -window_group %g -title "%l of %f" "tmp:%o"' />
<delegate encode="zip" restrain="True" command='|gzip -cf > "%o"' />
</delegatemap>
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert bmp to svg

Post by snibgo »

edepperson wrote:C:\WebSites\CBT\CBT\Media\4\13\Slides>C:\ProgramDownloads\Autotrace\autotrace.exe -input-format=bmp -output-format=svg -output-file=EGBTraining_001.svg EGBtraining_001.bmp

Error reading BMP file header
Why have you inserted all those equals signs (=)? Try it without.

Perhaps autotrace can't read that BMP file, perhaps because the format is newer than the autotrace program. You might try using IM to convert the BMP to TGA, or one of the other formats, and see if autotrace can read that.
snibgo's IM pages: im.snibgo.com
edepperson
Posts: 8
Joined: 2014-05-02T07:29:51-07:00
Authentication code: 6789

Re: convert bmp to svg

Post by edepperson »

the equal sign was suggested first in the README doc, the space was suggested second.
I tried it without the equal sign, got the same error.
changed to tga (which is a valid file, I can open it in Pain.NET, as I also could with the bmp) Got the following results

C:\ProgramDownloads\Autotrace\autotrace -input-format tga -output-format svg -output-file EGBTraining_001.svg EGBtraining_001.tga
TGA: eroor reading file

I am trying to convert a 24 bitmap, could that be the problem? Can Potrace convert color bmp to svg?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert bmp to svg

Post by snibgo »

Someone who knows about autotrace can help you more than I can. Sorry.

Potrace traces the boundary between black and white, typically at the 50% contour. It reads colour files but doesn't know about colours; it is only concerned with the 50% contour.
snibgo's IM pages: im.snibgo.com
edepperson
Posts: 8
Joined: 2014-05-02T07:29:51-07:00
Authentication code: 6789

Re: convert bmp to svg

Post by edepperson »

Thanks for trying, maybe someone else will pick up on this
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert bmp to svg

Post by fmw42 »

I don't think autotrace knows about colors either. Mostly, it is done by separating colors into binary masks and then converting to vectors keeping track of the color. Then compositing all the vectors together. At least that is my understanding. Though I am not an expert on either autotrace or potrace.
rich2005
Posts: 32
Joined: 2012-04-09T11:07:36-07:00
Authentication code: 8675308

Re: convert bmp to svg

Post by rich2005 »

From past tests and AFAIK autotrace does not work in M$ Win after WinXP. It does work in linux (at least the 32 bit PCLOS I use)

Potrace works but does not have a centerline option, which is a big miss.

Autotrace is sometimes picky about the input file format, example if saving bmp from gimp enable 'do not save color space info'

TGA seems to work OK, some output, and it did not matter if the file is rle compressed or not.

[rich@localhost ramdisk]$ autotrace -color-count 2 -output-format svg -output-file 1.svg -report-progress 1.tga
TGA: too much input data, ignoring extra datum
1.tga ||||||||||||||||||||||||||||||||||||||||||||||||||
[rich@localhost ramdisk]$ autotrace -color-count 2 -output-format svg -output-file 2.svg -report-progress 2.tga
TGA: too much input data, ignoring extra datum
2.tga ||||||||||||||||||||||||||||||||||||||||||||||||||
[rich@localhost ramdisk]$ autotrace -color-count 2 -output-format svg -output-file 3.svg -report-progress 3.bmp
3.bmp ||||||||||||||||||||||||||||||||||||||||||||||||||
[rich@localhost ramdisk]$

A couple of warning message but all the out svg files are the same size. for comparison bmp is 1.2 MB; svg is 2.8 KB
edepperson
Posts: 8
Joined: 2014-05-02T07:29:51-07:00
Authentication code: 6789

Re: convert bmp to svg

Post by edepperson »

Thank for the feedback. Thedev environment is Windows 7 and the server environment if Win 2008 R2, so I guess autotrace is out. I can't use Potrace because I need color. Are there any other options to use with IM?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert bmp to svg

Post by snibgo »

edepperson wrote:I can't use Potrace because I need color. Are there any other options to use with IM?
What do you want to accomplish? Potrace doesn't look for colour boundaries, so you can use IM to make these into black/white boundaries. For example, we can reduce an image to (n) colours, then loop through these colours making it black and everything else white, and potrace makes a path out of the colour. I convert each mono-coloured SVG into a PNG and flatten them together, which more or less reconstitutes the original image. Windows BAT script:

Code: Select all

set SRC=\prose\pictures\st_src_sm.jpg

set PNG_LIST=

%IM%convert ^
  %SRC% ^
  -blur 0x4 ^
  +dither ^
  -colors 9 ^
  -write x0.png ^
  -unique-colors txt:tCOLS.txt

for /F "usebackq skip=1 tokens=3 delims= " %%C in (tCOLS.txt) ^
do (
  echo %%C

  %IM%convert ^
    x0.png ^
    +transparent %%C ^
    -fill Black -opaque %%C ^
    -background White -flatten ^
    x.pnm

  %POTRACEDIR%potrace --color %%C -s -o x.svg x.pnm

  %IM%convert ^
    -background None x.svg ^
    -background %%C -alpha background ^
    x_%%C.png

  set PNG_LIST=!PNG_LIST! x_%%C.png
)

%IM%convert %PNG_LIST% -background None -flatten xs.png
snibgo's IM pages: im.snibgo.com
edepperson
Posts: 8
Joined: 2014-05-02T07:29:51-07:00
Authentication code: 6789

Re: convert bmp to svg

Post by edepperson »

It appears what you are doing is using svg to obtain the quality you want and then saving that as a bitmap. That is not what I'm trying to accomplish. What I want is to convert an image to svg and use the svg version of the image on a web page
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert bmp to svg

Post by snibgo »

I converted the SVGs back to PNG to show that the roundtrip in colour works. Of course, you can do anything more useful with the SVG files. For example, they can be combined by simple text processing.
snibgo's IM pages: im.snibgo.com
Post Reply