-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelper.min.js
More file actions
1 lines (1 loc) · 3.45 KB
/
helper.min.js
File metadata and controls
1 lines (1 loc) · 3.45 KB
1
window.downloadFromUrl=options=>{const anchorElement=document.createElement("a");anchorElement.href=options.url;anchorElement.download=options.fileName??"";anchorElement.click();anchorElement.remove()};window.getPolygonImage=(sourceCanvas,path)=>{const canvas=document.createElement("canvas"),context=canvas.getContext("2d"),width=sourceCanvas.width,height=sourceCanvas.height;canvas.width=width;canvas.height=height;context.imageSmoothingEnabled=!0;context.beginPath();context.moveTo(path[0]*width/100,path[1]*height/100);context.fillStyle="rgba(255, 255, 255, 0)";for(let i=2;i<path.length;i+=2)context.lineTo(path[i]*width/100,path[i+1]*height/100);return context.closePath(),context.clip(),context.fill(),context.globalCompositeOperation="lighter",context.drawImage(sourceCanvas,0,0,width,height),canvas.toDataURL("image/png",1)};window.getEllipseImage=sourceCanvas=>{const createdCanvas=document.createElement("canvas"),contextCanvas=createdCanvas.getContext("2d"),widthCanvas=sourceCanvas.width,heightCanvas=sourceCanvas.height;return createdCanvas.width=widthCanvas,createdCanvas.height=heightCanvas,contextCanvas.imageSmoothingEnabled=!0,contextCanvas.drawImage(sourceCanvas,0,0,widthCanvas,heightCanvas),contextCanvas.globalCompositeOperation="destination-in",contextCanvas.beginPath(),contextCanvas.ellipse(widthCanvas/2,heightCanvas/2,widthCanvas/2,heightCanvas/2,0*Math.PI,0,180*Math.PI,!0),contextCanvas.fill(),createdCanvas.toDataURL("image/png",1)};window.getEllipseImageInBackground=(sourceCanvas,dotNetImageReceiverRef,maximumReceiveChunkSize)=>{setTimeout(()=>{const newCanvas=document.createElement("canvas"),ctxCanvas=newCanvas.getContext("2d"),widthCanvas=sourceCanvas.width,heightCanvas=sourceCanvas.height;newCanvas.width=widthCanvas;newCanvas.height=heightCanvas;ctxCanvas.imageSmoothingEnabled=!0;ctxCanvas.drawImage(sourceCanvas,0,0,widthCanvas,heightCanvas);ctxCanvas.globalCompositeOperation="destination-in";ctxCanvas.beginPath();ctxCanvas.ellipse(widthCanvas/2,heightCanvas/2,widthCanvas/2,heightCanvas/2,0,0,2*Math.PI,!0);ctxCanvas.fill();newCanvas.toBlob(async blob=>{await window.cropper.readBlobInChunks(blob,dotNetImageReceiverRef,maximumReceiveChunkSize)},"image/png",1)},0)};window.getPolygonImageInBackground=(sourceCanvas,path,dotNetImageReceiverRef,maximumReceiveChunkSize)=>{setTimeout(()=>{const createdCanvas=document.createElement("canvas"),contextCanvas=createdCanvas.getContext("2d"),widthCanvas=sourceCanvas.width,heightCanvas=sourceCanvas.height;createdCanvas.width=widthCanvas;createdCanvas.height=heightCanvas;contextCanvas.imageSmoothingEnabled=!0;contextCanvas.beginPath();contextCanvas.moveTo(path[0]*widthCanvas/100,path[1]*heightCanvas/100);contextCanvas.fillStyle="rgba(255, 255, 255, 0)";for(let i=2;i<path.length;i+=2)contextCanvas.lineTo(path[i]*widthCanvas/100,path[i+1]*heightCanvas/100);contextCanvas.closePath();contextCanvas.clip();contextCanvas.fill();contextCanvas.globalCompositeOperation="lighter";contextCanvas.drawImage(sourceCanvas,0,0,widthCanvas,heightCanvas);createdCanvas.toBlob(async blob=>{await window.cropper.readBlobInChunks(blob,dotNetImageReceiverRef,maximumReceiveChunkSize)},"image/png",1)},0)};window.fillCanvasWithRandomColors=canvas=>{if(canvas){const ctx=canvas.getContext("2d"),width=canvas.width,height=canvas.height,imageData=ctx.createImageData(width,height),data=imageData.data;for(let i=0;i<data.length;i+=4)data[i]=Math.random()*255,data[i+1]=Math.random()*255,data[i+2]=Math.random()*255,data[i+3]=255;ctx.putImageData(imageData,0,0)}};