This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.onerror = function(e) { | |
console.log("error handled", e); | |
} | |
function funcWithError() { | |
a; // a is not defined | |
} | |
function test() { | |
funcWithError(); | |
console.log("hi"); // this will not be executed | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svgElement = document.getElementById('svg_element'); | |
let {width, height} = svgElement.getBBox(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let clonedSvgElement = svgElement.cloneNode(true); | |
// true for deep clone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let outerHTML = clonedSvgElement.outerHTML, | |
blob = new Blob([outerHTML],{type:'image/svg+xml;charset=utf-8'}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let URL = window.URL || window.webkitURL || window; | |
let blobURL = URL.createObjectURL(blob); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let image = new Image(); | |
image.onload = () => { | |
let canvas = document.createElement('canvas'); | |
canvas.widht = width; | |
canvas.height = height; | |
let context = canvas.getContext('2d'); | |
// draw image in canvas starting left-0 , top - 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let png = canvas.toDataURL(); // default png | |
let jpeg = canvas.toDataURL('image/jpg'); | |
let webp = canvas.toDataURL('image/webp'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var download = function(href, name){ | |
var link = document.createElement('a'); | |
link.download = name; | |
link.style.opacity = "0"; | |
document.append(link); | |
link.href = href; | |
link.click(); | |
link.remove(); | |
} | |
download(png, "image.png"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var download = function(href, name){ | |
var link = document.createElement('a'); | |
link.download = name; | |
link.style.opacity = "0"; | |
document.append(link); | |
link.href = href; | |
link.click(); | |
link.remove(); | |
} | |
download(png, "image.png"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let jpeg = canvas.toDataURL('image/jpg'); // 0.92 | |
let webp = canvas.toDataURL('image/webp', 0.5); |