async function svgUrlToPngDataUrlAsync(imageURL, scale = 1) {
    const img = new window.Image(),
        loadHandler = function(resolve, reject) {
            const canvas = window.document.createElement('canvas'),
                ctx = canvas.getContext && canvas.getContext('2d');

            canvas.height = img.height * scale;
            canvas.width = img.width * scale;
            ctx.drawImage(img, 0, 0, canvas.width, canvas.height);

            // Now we try to get the contents of the canvas.
            try {
                const ret = canvas.toDataURL('image/png');
                resolve(ret);
            } catch (e) {
                reject(e);
            }
        };

    return new Promise((resolve, reject) => {
        img.onload = () => loadHandler(resolve, reject);
        img.onerror = reject;
        img.src = imageURL;
    });
}
/**
 * Get PNG data:URL from image URL. Pass in callbacks to handle results.
 */
Get PNG data:URL from image URL. Pass in callbacks to handle results.
Get PNG data : URL from image URL . Pass in callbacks to handle results .
async function svgUrlToPngDataUrlAsync(imageURL, scale = 1) {
    const img = new window.Image(),
        loadHandler = function(resolve, reject) {
            const canvas = window.document.createElement('canvas'),
                ctx = canvas.getContext && canvas.getContext('2d');
            canvas.height = img.height * scale;
            canvas.width = img.width * scale;
            ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
            try {
                const ret = canvas.toDataURL('image/png');
                resolve(ret);
            } catch (e) {
                reject(e);
            }
        };
    return new Promise((resolve, reject) => {
        img.onload = () => loadHandler(resolve, reject);
        img.onerror = reject;
        img.src = imageURL;
    });
}
async function svgUrlToPngDataUrlAsync ( imageURL , scale = 1 ) { const img = new window . Image ( ) , loadHandler = function ( resolve , reject ) { const canvas = window . document . createElement ( 'canvas' ) , ctx = canvas . getContext && canvas . getContext ( '2d' ) ; canvas . height = img . height * scale ; canvas . width = img . width * scale ; ctx . drawImage ( img , 0 , 0 , canvas . width , canvas . height ) ; try { const ret = canvas . toDataURL ( 'image/png' ) ; resolve ( ret ) ; } catch ( e ) { reject ( e ) ; } } ; return new Promise ( ( resolve , reject ) => { img . onload = ( ) => loadHandler ( resolve , reject ) ; img . onerror = reject ; img . src = imageURL ; } ) ; }
Get PNG data:URL from image URL.
Get PNG data : URL from image URL .
// Now we try to get the contents of the canvas.