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

前端 未结 4 1118
情歌与酒
情歌与酒 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

    Most image file formats have unique bytes at the start. The unix file command looks at the start of the file to see what type of data it contains. See the Wikipedia article on Magic numbers in files and magicdb.org.

提交回复
热议问题