refactored pixel count function from _new_canvas.html.erb to canvas.js