If just looking for the JPEG type, maybe a simple fix to get rid of imghdr would be to look at the signature in the first few bytes of the image data like:
...
# Check for JPEG signature (first three bytes are b'\xFF\xD8\xFF')
if imagebytes.startswith(b'\xFF\xD8\xFF'):
return ImageEncoding.JPEG
return ImageEncoding.Unknown
The
imghdr
module is deprecated in Python 3.11 (see here) and slated for removal in Python 3.13.imghdr
is used to determine image type: https://github.com/SecurityInnovation/PGPy/blob/30a757181ab02f918a94f8549f354d93639b95e6/pgpy/constants.py#L430-L435If just looking for the JPEG type, maybe a simple fix to get rid of
imghdr
would be to look at the signature in the first few bytes of the image data like:?