Fixing bug in the resize, adding valid image check before adding it on the canvas