Skip to content

Instantly share code, notes, and snippets.

@jacomyal
Last active June 20, 2024 09:00
Show Gist options
  • Save jacomyal/6f37a25db647b807d4d9c5ce37301d33 to your computer and use it in GitHub Desktop.
Save jacomyal/6f37a25db647b807d4d9c5ce37301d33 to your computer and use it in GitHub Desktop.
Quick snippet to log ImageData in the Chrome JavaScript console
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