Created
September 2, 2021 11:31
-
-
Save rostegg/8954275933d3ae516e287a8a685dd723 to your computer and use it in GitHub Desktop.
Get ImageData from canvas, loading picture via url
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
const getImageDataFromUrl = (url, callback) => { | |
const canvas = document.createElement("canvas") | |
const context = canvas.getContext("2d") | |
const image = new Image() | |
image.onload = async () => { | |
const { width, height } = image | |
const { data: imageData } = context.getImageData(0, 0, width, height) | |
callback(imageData) | |
} | |
image.src = url | |
} | |
function log(data) { | |
console.log(data) | |
} | |
getImageDataFromUrl('https://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment