offscreen canvas js

Solutions on MaxInterview for offscreen canvas js by the best coders in the world

showing results for - "offscreen canvas js"
David
15 Nov 2018
1import Canvg, {
2    presets
3} from 'canvg';
4
5self.onmessage = async (event) => {
6    const {
7        width,
8        height,
9        svg
10    } = event.data;
11    const canvas = new OffscreenCanvas(width, height);
12    const ctx = canvas.getContext('2d');
13    const v = await Canvg.from(ctx, svg, presets.offscreen());
14
15    // Render only first frame, ignoring animations and mouse.
16    await v.render();
17
18    const blob = await canvas.convertToBlob();
19    const pngUrl = URL.createObjectURL(blob);
20
21    self.postMessage({
22        pngUrl
23    });
24};