@@ -187,6 +187,28 @@ def _find_jpeg_exif(fh: BinaryIO, data, fake_exif) -> tuple:
187187 return offset , endian , fake_exif
188188
189189
190+ def _find_png_exif (fh : BinaryIO , data : bytes ) -> tuple :
191+ logger .debug ("PNG format recognized in data[0:8]=%s" , data [:8 ].hex ())
192+ fh .seek (8 )
193+
194+ while True :
195+ data = fh .read (8 )
196+ chunk = data [4 :8 ]
197+ logger .debug ("PNG found chunk %s" , chunk .decode ("ascii" ))
198+
199+ if chunk == b"" or chunk == b"IEND" :
200+ break
201+
202+ if chunk == b"eXIf" :
203+ offset = fh .tell ()
204+ return offset , fh .read (1 )
205+
206+ chunk_size = int .from_bytes (data [:4 ], "big" )
207+ fh .seek (fh .tell () + chunk_size + 4 )
208+
209+ raise ExifNotFound ("PNG file does not have exif data." )
210+
211+
190212def _get_xmp (fh : BinaryIO ) -> bytes :
191213 xmp_bytes = b''
192214 logger .debug ('XMP not in Exif, searching file for XMP info...' )
@@ -231,6 +253,8 @@ def _determine_type(fh: BinaryIO) -> tuple:
231253 elif data [0 :2 ] == b'\xFF \xD8 ' :
232254 # it's a JPEG file
233255 offset , endian , fake_exif = _find_jpeg_exif (fh , data , fake_exif )
256+ elif data [0 :8 ] == b'\x89 PNG\r \n \x1a \n ' :
257+ offset , endian = _find_png_exif (fh , data )
234258 else :
235259 # file format not recognized
236260 raise ExifNotFound ("File format not recognized." )
0 commit comments