Is there a way to infer what image format a file is, without reading the entire file?

前端 未结 4 1119
情歌与酒
情歌与酒 2021-02-20 00:19

Is there a good way to see what format an image is, without having to read the entire file into memory?

Obviously this would vary from format to format (I\'m particular

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 00:51

    Either file on the *nix command-line or reading the initial bytes of the file. Most files come with a unique header in the first few bytes. For example, TIFF's header looks something like this:

    0x00000000: 4949 2a00 0800 0000
    For more information on the TIFF file format specifically if you'd like to know what those bytes stand for, go here.

提交回复
热议问题