How can I tell if an extensionless image is png or

2019-04-10 06:15发布

A while ago I saved some images generated by a web service so the file names are e.g 'ysauyft87ggsa67fgeg&w=1600'. I can open and manipulate these images OK, I'd just like to know what encoding they are (it's almost certainly png or jpeg). I've tried 'get info' in OSX, but it thinks the files are just text (even though it generates thumbnails correctly and I can view the images in preview). If I serve the images on a server they are delivered as 'application/octet-stream'.

How can I easily determine whether they are png or jpeg via the shell?

2条回答
够拽才男人
2楼-- · 2019-04-10 06:25

Three methods:

查看更多
劳资没心,怎么记你
3楼-- · 2019-04-10 06:35

The "magic code" for a

  • PNG file should begin with 89 50 4E 47 0D 0A 1A 0A
  • JPEG files begin with FFD8 and end with FFD9
查看更多
登录 后发表回答