@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 614 B
JavaScript
import{loadImage as o}from"./loadImage";export function isSvgBlob(n){return n.type.startsWith("image/svg+xml")}export async function rasterizeSvg(n){const t=URL.createObjectURL(n);try{const e=await o(t);if(!e?.naturalWidth||!e.naturalHeight)return null;const a=document.createElement("canvas");a.width=e.naturalWidth,a.height=e.naturalHeight;const r=a.getContext("2d");return r?(r.drawImage(e,0,0),a):null}finally{URL.revokeObjectURL(t)}}export async function svgToPngBlob(n){const t=await rasterizeSvg(n);return t?i(t):null}function i(n){return new Promise(t=>{try{n.toBlob(e=>t(e),"image/png")}catch{t(null)}})}