Resizing and generating images using HTML5 and Canvas