1

I need to convert a .wmf file to a .png format.

I can't use libraries under the *GPL license.

Solutions that use external dependencies (such as inkscape or libreoffice in a subprocess) are also not suitable for my project. Using external libraries in the system(installed by apt or another package manager, not by pip) is also undesirable.

I tried using Pillow, but it gives out an OSError (because the project runs on Linux, and Pillow supports .wmf only on Windows):

from PIL import Image

def main():
    img = Image.open('test.wmf')
    img.save('test.png')

if __name__ == '__main__':
    main()

OSError: cannot find loader for this WMF file.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Meetinger
  • 165
  • 8
  • It's not impossible to parse wmf yourself, but it's not easy either. Good luck. – Mark Ransom May 26 '23 at 17:47
  • Can `https://pypi.org/project/pyopencv/` do it? – Pete May 26 '23 at 18:04
  • Raises this error: `cv2.error: OpenCV(4.7.0) /io/opencv/modules/highgui/src/window.cpp:971: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'` – Meetinger May 26 '23 at 18:24
  • @pete "pyopencv" "Released: Sep 25, 2010". you got the wrong package. and no, OpenCV isn't meant to handle any niche image format, and it does not handle this WMF thing. look for a library that is _just_ for image file reading/writing. imagemagick comes to mind. also, if WMF is a vector format, then all the usual "image processing" is inapplicable. you first have to ***rasterize*** the vector data into raster data. I don't think you realize the computational complexity of this task, or the decisions you as the user have to make for that to go well. – Christoph Rackwitz May 26 '23 at 20:34
  • Here's the spec if you want to do it yourself: https://www.loc.gov/preservation/digital/formats/digformatspecs/WindowsMetafileFormat(wmf)Specification.pdf. Probably find something that rasterizes it to .jpg or another raster format that can then be converted to .jpg. – Pete May 26 '23 at 21:22

0 Answers0