draw-round-image.js 496 B

123456789101112131415
  1. /** 绘制圆角图片原型方法 */
  2. export default {
  3. name: 'drawRoundImage',
  4. handle: async (canvas, ctx, url, x, y, w, h, r = 15) => {
  5. var _a;
  6. ctx.save();
  7. (_a = ctx.setFillStyle) === null || _a === void 0 ? void 0 : _a.call(ctx, 'transparent');
  8. ctx.fillStyle = 'transparent';
  9. ctx.fillRoundRect(x, y, w, h, r);
  10. ctx.clip();
  11. const result = await ctx.drawImage(url, x, y, w, h);
  12. ctx.restore();
  13. return result;
  14. }
  15. };