Don't write outside of a context

Some implementations (eg. node-canvas) do not correctly handle writing (putImageData) of image data outside context bounds. Fixes #4267.