You only get a directory and corresponding file name retention if you use --wrap-with-directory on the ipfs add command. Otherwise the data extension is not saved anywhere, but the data encoding is derived by rummaging through the actual file contents.
And if you do use --wrap-with-directory, then the returned CID is of the directory and you need to use /ipfs//<file.ext> to retrieve the actual file.
# save to file
ipfs cat <hash> > theimagefile
# save to file option 2
ipfs get <hash>
# Try to guess file type
# Try to get filetype option 2
# open http://localhost:8080/ipfs/hash
# Finally: open file with your favourite tool