Skip to content

imghdr is deprecated and slated for removal in Python 3.13 #462

@elibon99

Description

@elibon99

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:

PGPy/pgpy/constants.py

Lines 430 to 435 in 30a7571

@classmethod
def encodingof(cls, imagebytes):
type = imghdr.what(None, h=imagebytes)
if type == 'jpeg':
return ImageEncoding.JPEG
return ImageEncoding.Unknown # pragma: no cover

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

?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions