Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Doesn't work unless the image host accepts CORS
window.download = a => {
const { opacity, country, blendMode } = current
const canvas = document.createElement('canvas')
canvas.width = 1280
canvas.height = 720
const ctx = canvas.getContext('2d')
ctx.clearRect(0, 0, 1280, 720)
ctx.globalCompositeOperation = 'source-over'
const img = document.createElement('img')
img.crossOrigin = "use-credentials"
img.src = currentImage()
ctx.drawImage(img, 0, 0, 1280, 720)
console.log(flags(opacity)[country])
const [_, svgUrl] = /^.*url\("(.*)"\).*$/m.exec(flags(opacity)[country])
console.log(svgUrl)
if (svgUrl) {
img.src = svgUrl
ctx.globalCompositeOperation = blendMode
ctx.drawImage(img, 0, 0, 1280, 720)
}
document.body.appendChild(canvas)
a.href = canvas.toDataURL()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.