title: Keep paint within image boundaries
body: <p>I am building a kid's Paint application for iPad. Basically I have made a canvas which has an image and, using Mouse Event, one can color on it. However, I do not want the color to get outside of the boundaries of my image. How is that possible?</p>
  
  <p>My app code is quite similar to <a href="http://cool-php-tutorials.blogspot.co.uk/2011/05/simple-html5-drawing-app-with-saving.html" rel="nofollow">this sample code</a>.</p>