In the first case, we had some code that wasn't working because it expected a data file to be in all upper case. When we started getting data with mixed upper and lower case, the program broke. I've stuck with it for these short little tasks. Maybe you'll find a need for it too. The magic file is a text file that contains some identifying characteristics of a large number of file types.
Most files have some key identifier so that other applications can figure out what they are.
Linux applications tend to take advantage of that fact, rather than simply relying on the file's extension. File prints the version number according to that. Finally, it uses the pairs of bytes at offsets 6 and 8 to display the width and height of the image. See my example output above for the full output for a GIF file example. If you're generating output as part of a program you've developed, you can add its magic info to that file.