Created
October 15, 2024 15:06
-
-
Save stepankuzmin/e44a701a02361401d0aa5fabd6ca69fd to your computer and use it in GitHub Desktop.
Log OffscreenCanvas rendering Context in the browser 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
export function logOffscreenCanvasContext(context, scaleFactor = 1) { | |
const canvas = document.createElement('canvas'); | |
canvas.width = context.canvas.width; | |
canvas.height = context.canvas.height; | |
const ctx = canvas.getContext('2d'); | |
ctx.drawImage(context.canvas, 0, 0); | |
const displayWidth = canvas.width * scaleFactor; | |
const displayHeight = canvas.height * scaleFactor; | |
console.log('%c ', ` | |
font-size: 1px; | |
padding: ${displayHeight / 2}px ${displayWidth / 2}px; | |
line-height: 0; | |
background: url(${canvas.toDataURL()}) no-repeat center; | |
background-size: ${displayWidth}px ${displayHeight}px; | |
border: 1px solid red; | |
`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment