Close file handle if exception occurs in image class

ref #10392
Merge pull request #10394 from owncloud/close-filehandle-lib-image

Close file handle if exception occurs in image class