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

[html] 第349天 使用canvas制作一个印章 #2159

Open
haizhilin2013 opened this issue Mar 29, 2020 · 1 comment
Open

[html] 第349天 使用canvas制作一个印章 #2159

haizhilin2013 opened this issue Mar 29, 2020 · 1 comment
Labels
html html

Comments

@haizhilin2013
Copy link
Collaborator

第349天 使用canvas制作一个印章

我也要出题

@haizhilin2013 haizhilin2013 added the html html label Mar 29, 2020
@hellojackhui
Copy link

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
</body>

<script>
    var dataUrl = '';
    function createStampUrl() {
      var canvas = document.createElement('canvas');
      canvas.width = 300;
      canvas.height = 200;
      canvas.setAttribute('width', 300);
      canvas.setAttribute('height', 200);
      var ctx = canvas.getContext('2d');

      ctx.beginPath();
      ctx.ellipse(150, 100, 100, 50, 0, 0, Math.PI * 2);
      ctx.fillStyle = "red";
      ctx.strokeStyle = "red";
      ctx.fill();
      ctx.stroke();
      ctx.closePath();

      ctx.beginPath();
      ctx.ellipse(150, 100, 90, 40, 0, 0, Math.PI * 2);
      ctx.fillStyle = "white";
      ctx.fill();
      ctx.stroke();
      ctx.closePath();

      ctx.beginPath();
      ctx.ellipse(150, 100, 70, 30, 0, 0, Math.PI * 2);
      ctx.strokeStyle = "red";
      ctx.lineWidth = 2;
      ctx.stroke();
      ctx.closePath();


      ctx.font = "14px Microsoft YaHei";
      ctx.fillStyle = "red";
      ctx.fillText("hello canvas", 110, 105);

      dataUrl = canvas.toDataURL("image/jpeg");

      var app = document.querySelector("#app");
      app.style.width = "300px";
      app.style.height = "300px";
      app.style.backgroundImage = `url(${dataUrl})`;
      app.style.backgroundRepeat = 'no-repeat';
    }
    createStampUrl();
</script>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
html html
Projects
None yet
Development

No branches or pull requests

2 participants