Question: Weird issue when using 'no-repeat', 'repeat-x' or 'repeat-y' when creating a pattern using an image.
Consider the following:

```
<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
    </style>
  </head>
  <body>
    <canvas id="myCanvas" width="578" height="200"></canvas>
    <script>
      var canvas = document.getElementById('myCanvas');
      var context = canvas.getContext('2d');

      var imageObj = new Image();
      imageObj.onload = function() {        

        context.rect(0, 0, canvas.width, canvas.height);
        context.translate(50,50);

        var pattern = context.createPattern(imageObj, 'no-repeat');
        context.fillStyle = pattern;
        context.fill();
      };
      imageObj.src = 'http://www.html5canvastutorials.com/demos/assets/wood-pattern.png';
    </script>
  </body>
</html>  

```

I'm translating the image pattern within the shape (in this case it's a rectangle, but it occurs for any shape). On Chrome 35.0.1916.114 m, it causes a 'smearing' of the image. Is there a way to avoid the smear effect or am I doing something insanely wrong.

[Fiddle](https://jsfiddle.net/bHcL9/5/)
---------------------------------------

screen shot:  

[![Example Screen Shot](https://i.stack.imgur.com/o95rk.png)](https://i.stack.imgur.com/o95rk.png)

Answer: 
`context.translate` applies to the starting point to draw on the canvas. Instead you want to fill a certain portion of the rectangle.

```
imageObj.onload = function() {
  var width = 600;
  var height = 400;
  var patOffsetX = 50;
  var patOffsetY = 50;

  context.rect(0, 0, width, height);

  var pattern = context.createPattern(imageObj, 'repeat');
  context.fillStyle = pattern;
  context.fillRect(patOffsetX, patOffsetY, width - patOffsetX, height - patOffsetY);
  context.stroke(); //added to help see the rect
};

```

I also updated the size of the canvas to see it working.

```
<canvas id="myCanvas" width="800" height="400"></canvas>

```

[**Fiddle**](http://jsfiddle.net/bHcL9/9/)
You can accomplish your task using clipping 

* Save the context state.
* Draw a boundary rectangle.
* Clip future drawing to inside the boundary rectangle.
* Draw another offset rectangle inside the boundary rectangle using your image as a pattern.
* Restore the context to its unclipped state.

A Demo: <http://jsfiddle.net/m1erickson/fHKLk/>

![enter image description here](https://i.stack.imgur.com/Fc9Sp.png)

Example code:

```
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" 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 context=canvas.getContext("2d");

    var img=new Image();
    img.onload=start;
    img.src="https://dl.dropboxusercontent.com/u/139992952/stackoverflow/house16x16.png";
    function start(){

        // create a pattern
        var pattern = context.createPattern(img,'repeat');

        // save the unclipped context state
        context.save();

        // draw the boundary rect
        context.beginPath();
        context.rect(20,20,200,200);
        context.stroke();

        // clip future drawing to inside the boundary rect
        context.clip();

        // draw a 2nd rect with a 50px offset from the boundary rect
        // and using your image pattern
        context.fillStyle=pattern;
        context.fillRect(20+50,20+50,300,300);

        // restore the context to its unclipped state
        context.restore();
    }

}); // end $(function(){});
</script>
</head>
<body>
    <canvas id="canvas" width=300 height=300></canvas>
</body>
</html>

```