如何用图案填充图像

MD *_*AIN 10 php jquery html5 html5-canvas fabricjs

让我说我有一个形象! 在此输入图像描述

现在我想填写那个图像 在此输入图像描述

而我的最终形象应该是这样的在此输入图像描述

怎么做?到目前为止,我能够改变该图像的颜色,但无法填充图案.

我可以用html5画布(模式)吗?有没有办法用PHP或任何网络平台做到这一点.

mar*_*rkE 11

使用以下步骤创建模拟将映射模式应用于衬衫:

  • 创建衬衫的高对比度版本.
  • DrawImage那件衬衫在画布上
  • 将globalCompositeOperation设置为"source-atop"
  • (任何新图纸只会出现在衬衫图像不透明的地方)
  • 从方格图像创建图案
  • 用方格图案填充画布
  • (它只会出现在不透明的衬衫上)
  • 将globalAlpha设置为一个非常低的值
  • 反复绘制高对比度衬衫的图像
  • (这有效地叠加了衬衫"皱纹")

在此输入图像描述

为了更好的解决方案

创建衬衫的"凹凸贴图"并将其应用于three.js中的方格图案

这是代码和小提琴:http://jsfiddle.net/m1erickson/kzfKD/

<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script src="http://code.jquery.com/jquery.min.js"></script>

<style>
    body{ background-color: ivory; }
    canvas{border:1px solid red;}
</style>

<script>
$(function(){

    var canvas=document.getElementById("canvas");
    var ctx=canvas.getContext("2d");

    var img1=new Image();
    var img=new Image();
    img.onload=function(){

        img1.onload=function(){
            start();
        }
        img1.src="https://dl.dropboxusercontent.com/u/139992952/stackoverflow/4jiSz1.png";
    }
    img.src="https://dl.dropboxusercontent.com/u/139992952/stackoverflow/BooMu1.png";

    function start(){

        ctx.drawImage(img1,0,0);

        ctx.globalCompositeOperation="source-atop";

        ctx.globalAlpha=.85;

        var pattern = ctx.createPattern(img, 'repeat');
        ctx.rect(0, 0, canvas.width, canvas.height);
        ctx.fillStyle = pattern;
        ctx.fill();

        ctx.globalAlpha=.15;
        ctx.drawImage(img1,0,0);
        ctx.drawImage(img1,0,0);

    }


}); // end $(function(){});
</script>

</head>

<body>
    <canvas id="canvas" width=436 height=567></canvas>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)