Fix #53: imread doesn't close the file it opens.
Removed useless magicbuf parameter.
Safer stream opening.

Also, imwrite shouldn't close what it didn't open.