title: Canvas clearRect with rounded corners
body: <p>I have cut out a rectangular of a canvas with <code>ctx.clearRect()</code>. It produces a rectangular transparent area in the image. But is there a possibility to cut it out with rounded corners? </p>
  
  <p>Just like this:</p>
  
  <p><a href="https://i.stack.imgur.com/gKep9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gKep9.png" alt="Just click here"></a></p>
  
  <p>My Code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function createHolesInBg() {
      // overlay the image on the video and cut holes to see through to the video
      var image = document.getElementById('bg-one');
      var canvas = document.getElementById("window-canvas");
      var ctx = canvas.getContext("2d");
    
      ctx.drawImage(image, 0, 0);
  
      window.setTimeout(function() {
        ctx.clearRect(390, 150, 400, 300);
      }, 0);
  };
  
  // show video for 5 seconds and then start to cut some holes overlay bg
  window.setTimeout(function() {
    createHolesInBg();
  }, 0);
  
  // mute the video after 15 seconds as its gets annoying in blog post
  window.setTimeout(function() {  
    var video = document.getElementById("video-elm");
  video.muted = false;
  }, 0);</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    background-color: #000;
    margin: 0;
    padding: 0;
  }
  
  #window-canvas { pointer-events: none; }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;!-- background video --&gt;
  &lt;div stlye="position:absolute; top:0; left: 0;"&gt;
   &lt;video width="1180" height="620" controls autoplay loop id="video-elm"&gt;
    &lt;source src="https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"&gt;
    Your browser does not support HTML5 video.
  &lt;/video&gt;  
  &lt;/div&gt; 
  
  &lt;!-- canvas layer --&gt;
  &lt;canvas id="window-canvas" height="620" width="1280" style="position: absolute; top:0; left:0;"&gt;&lt;/canvas&gt;
  
  &lt;!-- hidden foreground image for use by Canvas --&gt;
  &lt;img src="https://i.pinimg.com/originals/0c/80/b6/0c80b6dfc2b311bac185c0b310bb18da.jpg" style="position: absolute; top:0; left:0; display:none;" id="bg-one"&gt;</code></pre>
  </div>
  </div>
  </p>