Do you need to handle any image decoding error? Also it would be nice to check that naturalWidth / Height of the image is not 0,0 in onload.