Last active
June 20, 2024 09:00
-
-
Save jacomyal/6f37a25db647b807d4d9c5ce37301d33 to your computer and use it in GitHub Desktop.
Quick snippet to log ImageData in the Chrome JavaScript console
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
function logImageData(imageData, size = 0) { | |
const canvas = document.createElement("canvas"); | |
canvas.width = size || imageData.width; | |
canvas.height = size || imageData.height; | |
const ctx = canvas.getContext("2d"); | |
if (!ctx) throw new Error("Could not get 2d context"); | |
ctx.putImageData(imageData, 0, 0); | |
const dataURL = canvas.toDataURL(); | |
console.log( | |
`%c `, | |
`font-size: ${size || imageData.height}px; background: url(${dataURL}); background-size: contain;`, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment