Created
March 27, 2017 03:18
-
-
Save geelen/699b6ae68338c2fcbc5e0a347f2ab9fb to your computer and use it in GitHub Desktop.
This file contains 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
// 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