|  | @@ -1,10 +1,11 @@
 | 
	
		
			
				|  |  |  import imgList from './images/logoWatermark.png'
 | 
	
		
			
				|  |  |  export const imgToCanvas = async (url: string) => {
 | 
	
		
			
				|  |  | +  console.log('imgToCanvas',url)
 | 
	
		
			
				|  |  |    const img = document.createElement('img')
 | 
	
		
			
				|  |  | +  img.setAttribute('crossOrigin', 'anonymous')
 | 
	
		
			
				|  |  | +  img.src = url+`?${new Date().getTime()}`
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  img.src = url
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  img.setAttribute('crossOrigin', 'anonymous') // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
 | 
	
		
			
				|  |  | + // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    await new Promise(resolve => (img.onload = resolve))
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -32,15 +33,16 @@ export const imgToCanvas = async (url: string) => {
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  export const addWatermark = async (canvas, text) => {
 | 
	
		
			
				|  |  | +  console.log('addWatermark')
 | 
	
		
			
				|  |  |    try {
 | 
	
		
			
				|  |  |      const ctx = canvas.getContext('2d')
 | 
	
		
			
				|  |  |      // ctx.fillStyle = '#fff'
 | 
	
		
			
				|  |  |      const img = document.createElement('img')
 | 
	
		
			
				|  |  | +    img.setAttribute('crossOrigin', 'anonymous')
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    img.src = imgList
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    // img.setAttribute('crossOrigin', 'anonymous') // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
 | 
	
		
			
				|  |  | +    img.src = imgList+`?${new Date().getTime()}`
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +   // 防止跨域引起的 Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
 | 
	
		
			
				|  |  |      await new Promise(resolve => (img.onload = resolve))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // 创建canvas DOM元素,并设置其宽高和图片一样
 | 
	
	
		
			
				|  | @@ -66,9 +68,10 @@ export const addWatermark = async (canvas, text) => {
 | 
	
		
			
				|  |  |      const pat = ctx.createPattern(water, 'repeat')
 | 
	
		
			
				|  |  |      ctx.fillStyle = pat
 | 
	
		
			
				|  |  |      ctx.fillRect(0, 0, canvas.width, canvas.height)
 | 
	
		
			
				|  |  | -    console.log('加水印',canvas)
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      return canvas
 | 
	
		
			
				|  |  |    } catch (e) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      console.log(e)
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 |