Last Updated: February 25, 2016
· graux

High quality EMF/WMF to PNG in Linux

I have been looking for long how to automatically convert several images included inside a docx document to PNG in order to be imported by my webapp.

If you have been trying or you intend to find a solution, I recommend you to read the great article:

High-res batch convert EMZ / WMZ grahpics to PNG a.k.a. "liberating your graphics"
by Hans Kwint:

Even using the methods described in the article, it is really difficult to generate a high quality conversion in Linux.

After many experiments I have achieved to success and convert the WMF/EMF files in high resolution to PNG/JPG. For those that are familiar with unoconv, you might know that you can convert these annoying files to PNG/JPG. But the quality sucks.

The work around that I have found consists in converting the WMF/EMF to PDF first with unoconv, and then finish the job with Image Magick. Using this approach the first conversion maintains the resolution of the original image, therefore you can convert to PNG using the original resolution/quality of the EMF/WMF image.

Using Image Magick you can remove the white margins that unoconv adds when converting to either PNG directly or to PDF. You can achieve this by using the parameter -trim.


unoconv -f pdf -o image10.pdf image10.wmf
convert -density 300 -trim -bordercolor white -border 5 image10.pdf image10.png

Here I add a 5 pixel border to not trim too much the image. The density is set to 300, of course if the original image resolution is not good, this will stretch the image.

I hope this can be helpful to someone

2 Responses
Add your response

Many thanks for this.
In my case I just used unoconv and after that I import the PDF to GIMP

over 1 year ago ·

This was a life-saver for me! Thanks so much :-)

over 1 year ago ·