Function: Identify Image

This is from a very old post of mine, posted for archival purposes.

Ever decide you had to hide an image file and you decide to change the extension to something like “.exe”, or perhaps, you used something like Signal messenger and downloaded an image but it didn’t have a valid extension?

Back in 2013, I wrote a function that uses something called “Magic Numbers” — or specific binary sequences within a file, that essentially “sign” the file as a specific data type.

This script, when passed a filename, will parse that file and output an array of information, such as the extension(s) used, type (raster/vector), the media type (previously called MIME type, and referred to as “mime” in this old code), and finally if it is lossy, lossless, or the colors are derived from a palette.

Download from GitHub.







Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.