Refactor and image scaling with canvas