Windows MetaFile (WMF) parser
npm install wmfProcessor for Windows MetaFile (WMF) files in JS (for the browser and nodejs).
With npm:
``bash`
$ npm install wmf
In the browser:
`html`
The browser exposes a variable WMF.
The data argument is expected to be an ArrayBuffer, Uint8Array or Buffer
- WMF.image_size(data) extracts the image offset and extents, returns an Array[width, height]
where both metrics are measured in pixels.
- WMF.draw_canvas(data, canvas) parses the WMF and draws to a Canvas.
- The library assumes the global ImageData is available. For nodejs-poweredcanvas
canvas implementations, a shim must be exposed as a global. Using the
npm package:
`js`
const { createImageData } = require("canvas");
global.ImageData = createImageData;
- OffscreenCanvas in Chrome and some other Canvas implementations require
the dimensions in the constructor:
`js`
const size = WMF.image_size(data);
const canvas = new OffscreenCanvas(size[0], size[1]);
Browser Fetch into canvas (click to show)
`jscanvas
// assume is a DOM element`
(async() => {
const res = await fetch("url/for/image.wmf");
const ab = await res.arrayBuffer();
WMF.draw_canvas(ab, document.getElementById("canvas"));
})();
NodeJS (using canvas
npm module) (click to show)
`js
const { createCanvas, createImageData } = require("canvas");
global.ImageData = createImageData;
const size = WMF.image_size(data);
const canvas = createCanvas(size[0], size[1]);
WMF.draw_canvas(data, canvas);
`
Please consult the attached LICENSE file for details. All rights not explicitly
granted by the Apache 2.0 License are reserved by the Original Author.
- MS-WMF`: Windows Metafile Format