Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More serious version #23

Open
the-baaron opened this issue Feb 28, 2021 · 0 comments
Open

More serious version #23

the-baaron opened this issue Feb 28, 2021 · 0 comments

Comments

@the-baaron
Copy link

the-baaron commented Feb 28, 2021

This is not a request or anything, just thought it could be useful for some:

I made this cleaned up version which allows to debug invisible canvas elements. I find it super useful like this when you're trying to debug canvas elements. Thanks!

just do console.canvas(ctx); and there you go

/**
 * Dubiously created by Adrian Cooney
 * http://adriancooney.github.io
 *
 * Made useful by Ronald Baars
 * https://baars.design
 */
(function (console) {
  "use strict";

  console.canvas = function (ctx, scale = 1) {
    const url = ctx.canvas.toDataURL();
    var img = new Image();

    img.onload = function () {
      const { height, width } = this;
      console.log(
        `%c+`,
        `
          font-size: 1px; 
          padding: ${Math.floor(height / 2)}px ${Math.floor(width / 2)}px;
          line-height: ${height}px;
          background: url(${url});
          background-size: ${width * scale}px ${height * scale}px;
          color: transparent;`
      );
    };

    img.src = url;
  };
})(console);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant