Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sheetjs/js-wmf
Windows MetaFile (wmf) processor
https://github.com/sheetjs/js-wmf
canvas image javascript wmf
Last synced: about 2 months ago
JSON representation
Windows MetaFile (wmf) processor
- Host: GitHub
- URL: https://github.com/sheetjs/js-wmf
- Owner: SheetJS
- License: apache-2.0
- Created: 2020-03-01T04:51:46.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-16T16:32:15.000Z (almost 5 years ago)
- Last Synced: 2024-10-29T22:37:40.526Z (about 2 months ago)
- Topics: canvas, image, javascript, wmf
- Language: TypeScript
- Homepage: https://oss.sheetjs.com/js-wmf
- Size: 88.9 KB
- Stars: 18
- Watchers: 3
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# js-wmf
Processor for Windows MetaFile (WMF) files in JS (for the browser and nodejs).
## Installation
With [npm](https://www.npmjs.org/package/wmf):
```bash
$ npm install wmf
```In the browser:
```html
```
The browser exposes a variable `WMF`.
## Usage
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`.
### Notes
- The library assumes the global `ImageData` is available. For nodejs-powered
canvas implementations, a shim must be exposed as a global. Using the `canvas`
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]);
```## Examples
Browser Fetch into canvas (click to show)
```js
// assume `canvas` 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);
```## License
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.## References
- `MS-WMF`: Windows Metafile Format