# 如何裁剪图片 (情景:选择头像)
Issue
欢迎在 Issue 中交流与讨论: Issue 231 (opens new window)
Author
var path = 'https://static-zh.wxb.com.cn/customer/form/2020/11/1758696796d.jpg'
function clipImage(path){
const canvas = document.createElement('canvas')
canvas.width = 200
canvas.height = 100
const ctx = canvas.getContext('2d')
const img = document.createElement('img')
img.src = path
img.setAttribute("crossOrigin",'Anonymous')
img.onload = function (){
ctx.drawImage(this,0,0,200,100)
console.log(canvas.toDataURL())
}
}
clipImage(path)