Page 1 of 2

Converting WMF to PNG

Posted: 2010-06-22T06:26:22-07:00
by dew930
I am trying to convert images from WMF to PNG format. What I really want to do is convert all the WMF files in a given directory, and all of its sub directories into the PNG format.
When I tried to convert a single image as a test, I get the following output. I am using windows. The files that I am trying to convert are located at "C:\clipart_test_magick".

Any help would be greatly appreciated.

Code: Select all

C:\clipart_test_magick>convert 2.png 2.WMF
Magick: unable to open image `png': No such file or directory @ error/blob.c/OpenBlob/2498.
Magick: no decode delegate for this image format `png' @ error/constitute.c/ReadImage/532.
Magick: missing an image filename `2.WMF' @ error/convert.c/ConvertImageCommand/2970.

Re: Converting WMF to PNG

Posted: 2010-06-22T06:42:54-07:00
by snibgo
Your command tries to read 2.png and create 2.wmf. You need to put the filenames in the opposite order.

Re: Converting WMF to PNG

Posted: 2010-06-22T07:05:05-07:00
by dew930
Thank you Snibgo, here is what results after doing "convert 2.wmf 2.png"

Code: Select all

C:\clipart_test_magick>convert 2.wmf 2.png
Magick: `%s' (%d) "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g58x50  "-sOutputFile=C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-htxHmeIQ" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-eYe7EDzG" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-x8t0G03f" @ error/utility.c/SystemCommand/2024.
Magick: `%s' (%d) "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g58x50  "-sOutputFile=C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-htxHmeIQ" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-eYe7EDzG" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-x8t0G03f" -c showpage @ error/utility.c/SystemCommand/2024.
Magick: Postscript delegate failed `C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-gaTG08bP': No such file or directory @ error/ps.c/ReadPSImage/779.
Magick: missing an image filename `2.png' @ error/convert.c/ConvertImageCommand/2970.

Re: Converting WMF to PNG

Posted: 2010-06-22T07:08:43-07:00
by snibgo
You need to install ghostscript. Then you might need to reinstall ImageMagick.

Re: Converting WMF to PNG

Posted: 2010-06-22T07:20:36-07:00
by dew930
Thank you again Snibgo, here is what results after doing "convert 2.wmf 2.png". I installed Ghostscript and reinstalled Image Magick (the latest versions of both).

Code: Select all

C:\clipart_test_magick>convert 2.wmf 2.png
Magick: `%s' (%d) "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g58x50  "-sOutputFile=C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-UDyY9uKz" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-LpH5RWon" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-N4Pq4CHX" @ error/utility.c/SystemCommand/2024.
Magick: `%s' (%d) "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g58x50  "-sOutputFile=C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-UDyY9uKz" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-LpH5RWon" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-N4Pq4CHX" -c showpage @ error/utility.c/SystemCommand/2024.
Magick: Postscript delegate failed `C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-yiuTEXnp': No such file or directory @ error/ps.c/ReadPSImage/779.
Magick: missing an image filename `2.png' @ error/convert.c/ConvertImageCommand/2970.

Re: Converting WMF to PNG

Posted: 2010-06-22T07:38:04-07:00
by snibgo
I can't recall the "official" way IM finds GS, but it works (for me, on Windows 7) when I put the GS location in the path.

1. Find gswin32c.exe

2. Put that in your path, either through the control panel, or eg:

Code: Select all

set PATH="c:\Program Files (x86)\gs\gs8.71\bin";%PATH%

Re: Converting WMF to PNG

Posted: 2010-06-22T07:48:15-07:00
by dew930
Thank you again Snibgo, here is what results after setting the path and trying to convert again.

Code: Select all

C:\clipart_test_magick>set PATH="C:\Program Files\gs\gs8.71\bin\gswin32.exe";%PATH%

C:\clipart_test_magick>convert 2.wmf 2.png
Magick: `%s' (%d) "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g58x50  "-sOutputFile=C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-FDK_446g" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-OW9tVjZf" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-xX4hFhT8" @ error/utility.c/SystemCommand/2024.
Magick: `%s' (%d) "gswin32c.exe" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g58x50  "-sOutputFile=C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-FDK_446g" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-OW9tVjZf" "-fC:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-xX4hFhT8" -c showpage @ error/utility.c/SystemCommand/2024.
Magick: Postscript delegate failed `C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/magick-EnH1jOZd': No such file or directory @ error/ps.c/ReadPSImage/779.
Magick: missing an image filename `2.png' @ error/convert.c/ConvertImageCommand/2970.

Re: Converting WMF to PNG

Posted: 2010-06-22T07:53:10-07:00
by snibgo
set PATH="C:\Program Files\gs\gs8.71\bin\gswin32.exe";%PATH%
PATH should contain directories, not filenames.

Re: Converting WMF to PNG

Posted: 2010-06-22T08:13:23-07:00
by dew930
Snibgo, I can't thank you enough. The files are now converting, but are the wrong size. The original WMF is 459 x 396 (checked with gimp), but the output PNG is 58x50. Image Magick appears to think the WMF is 58x50.

I looked at the supported formats and found WMF:

WMF R Windows Metafile Requires libwmf. By default, renders WMF files using the dimensions specified by the metafile header. Use the -density option to adjust the output resolution, and thereby adjust the output size. The default output resolution is 72DPI so -density 144 results in an image twice as large as the default. Use -background color to specify the WMF background color (default white) or -texture filename to specify a background texture image.

I then got the windows version of the libwmf library here http://sourceforge.net/projects/gnuwin3 ... e/download

Here is the output (the image still is not correct).

Code: Select all

C:\clipart_test_magick>set PATH="C:\Program Files\gs\gs8.71\bin\";%PATH%

C:\clipart_test_magick>convert 2.wmf 2.png

C:\clipart_test_magick>identify 2.wmf
2.wmf WMF 58x50 58x50+0+0 8-bit DirectClass 1.85KB 0.016u 0:00.015

Re: Converting WMF to PNG

Posted: 2010-06-22T08:23:00-07:00
by dew930
I also installed the libpng library. The output is the same.

Re: Converting WMF to PNG

Posted: 2010-06-22T08:23:26-07:00
by snibgo
Use the -density option to adjust the output resolution, and thereby adjust the output size.
Try:

Code: Select all

convert -density 288 2.wmf 2.png
I don't know anything about WMF files, but

Code: Select all

identify -vebose 2.wmf
might tell you something useful.

(I have to go out in a few minutes, back in a few hours.)

Re: Converting WMF to PNG

Posted: 2010-06-22T08:29:54-07:00
by dew930
The image is larger, but is still not the same size: 232 x 200 (the WMF was 459 x 396)

Code: Select all

C:\clipart_test_magick>convert -density 288 2.wmf 2.png

C:\clipart_test_magick>identify -vebose 2.wmf
Magick: unrecognized option `-vebose' @ error/identify.c/IdentifyImageCommand/817.

Re: Converting WMF to PNG

Posted: 2010-06-22T08:34:05-07:00
by snibgo
So, 469/232 * 288 = 570, so you need a density of 570.

Re: Converting WMF to PNG

Posted: 2010-06-22T08:38:00-07:00
by dew930
It worked! thank you Snibgo. The only issue now is when I try to do that for another image, the size is very disproportional. (from 177 x 108) to (1132 x 689). Is there anyway to automate it for when I put it in a loop?

Re: Converting WMF to PNG

Posted: 2010-06-22T14:12:05-07:00
by snibgo
I guess something in the metadata will help. If you post the URL to a WMF file, I can take a look.