Added better error handling to image resize routine