def test_jpeg(h, f): """JPEG data in JFIF or Exif format""" if h[6:10] in (b'JFIF', b'Exif'): return 'jpeg' どうやら、判定がうまく行かなかったファイルでは'JFIF'や'Exif'が正しい位置にはなかったようです。 解決方法 jpgファイルには、ファイル先頭が必ず FFD8 で始まる、というお約束があるのでそれを利用します。(なぜ imghdr がこの方法を取らないのかは気になるところです。)