Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop use of imghdr #443

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

drop use of imghdr #443

wants to merge 1 commit into from

Conversation

dkg
Copy link
Contributor

@dkg dkg commented Jun 14, 2023

imghdr is deprecated and will be removed in python 3.13 (see https://peps.python.org/pep-0594/#imghdr)

The relevant code in imghdr is just:

def test_jpeg(h, f):
    """JPEG data with JFIF or Exif markers; and raw JPEG"""
    if h[6:10] in (b'JFIF', b'Exif'):
        return 'jpeg'
    elif h[:4] == b'\xff\xd8\xff\xdb':
        return 'jpeg'

So we transplant it directly

imghdr is deprecated and will be removed in python 3.13 (see https://peps.python.org/pep-0594/#imghdr)

The relevant code in imghdr is just:

```
def test_jpeg(h, f):
    """JPEG data with JFIF or Exif markers; and raw JPEG"""
    if h[6:10] in (b'JFIF', b'Exif'):
        return 'jpeg'
    elif h[:4] == b'\xff\xd8\xff\xdb':
        return 'jpeg'
```

So we transplant it directly
@jbkkd
Copy link

jbkkd commented Sep 18, 2023

Any chance this could get merged in the near future?

@ktdreyer
Copy link

ktdreyer commented Oct 24, 2023

@Commod0re would you please merge this PR and ship a new release to PyPI?

I've confirmed that the implementation here matches test_jpeg() in /usr/lib64/python3.11/imghdr.py. Also, I tested this conditional on a random JPG image and imagebytes[6:10] is indeed b'JFIF'.

@etzelc
Copy link

etzelc commented Oct 15, 2024

Python 3.13 was released last week, and the imghdr module has been removed. https://www.python.org/downloads/release/python-3130/.

Are there any remaining blockers for this PR?

@sshishov
Copy link

We cannot move to Python3.13 because of this blocker.

But instead of copy-pasting the code, maybe we can try to use some alternatives proposed in PEP-0594?

These are the alternatives proposed there:

Hope that the issue will be resolved, either by "hardcoding" the old implementation or replacing with "supported" libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants