I have one image like this
, and I want to fill with such a template
to make such a result
.
I can fill out the template using the following code, but I don’t know how to draw a picture along the shape of the collar correctly, because it should look like real, but my result will be like this.
.
Here is my example script
$(function(){ drawCanvas("body","collar","images/collar.png", 180); function drawCanvas(overlayType, canvasID, imageSource, degreeRotate){ var canvas=document.getElementById(canvasID); var ctx=canvas.getContext("2d"); var imgBody=new Image(); var imgPattern=new Image(); imgPattern.onload=function(){ imgBody.onload=function(){ start(); } imgBody.src=imageSource; } imgPattern.src="images/pattern.png"; function start(){ ctx.drawImage(imgBody,0,0); if(overlayType=="body"){ ctx.globalCompositeOperation="source-atop"; ctx.globalAlpha=.85; var pattern = ctx.createPattern(imgPattern, 'repeat'); ctx.fillStyle = pattern; ctx.rect(0, 0, canvas.width, canvas.height); ctx.rotate(degreeRotate * Math.PI/180); ctx.fill(); ctx.translate(150,0); ctx.globalAlpha=.1; ctx.drawImage(imgBody,150,0); } } }});
Can someone lead me to how to control the curve shape along the collar shape to look like a real one?
source share