Created
November 10, 2021 09:45
-
-
Save simongong/e2cb762eb81dd9f7af50e3c2196eb391 to your computer and use it in GitHub Desktop.
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
function downloadIamge(imageSrc, name) { | |
var image = new Image() | |
image.setAttribute('crossOrigin', 'anonymous') | |
image.onload = function () { | |
var canvas = document.createElement('canvas') | |
canvas.width = image.width | |
canvas.height = image.height | |
var context = canvas.getContext('2d') | |
context.drawImage(image, 0, 0, image.width, image.height) | |
var url = canvas.toDataURL('image/png') | |
var a = document.createElement('a') | |
var event = new MouseEvent('click') | |
a.download = name || 'image_download' | |
a.href = url | |
a.dispatchEvent(event) | |
} | |
image.src = imageSrc | |
} | |
Array.from($("article img")).forEach((e,i)=>{ | |
downloadIamge(e.src, 'image'+i) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment