9

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?

wheresrhys
  • 20,222
  • 16
  • 83
  • 154

2 Answers2

26

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
ErstwhileIII
  • 4,691
  • 2
  • 21
  • 36
17

Three methods:

Gilles Quenot
  • 143,367
  • 32
  • 199
  • 195
ZalewaPL
  • 1,045
  • 1
  • 6
  • 13