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

Replace imghdr with something like filetype #11

Open
normanlorrain opened this issue Nov 14, 2022 · 3 comments
Open

Replace imghdr with something like filetype #11

normanlorrain opened this issue Nov 14, 2022 · 3 comments

Comments

@normanlorrain
Copy link
Owner

https://docs.python.org/3/library/imghdr.html (deprecated; good until Python 3.13)

filetype:
https://pypi.org/project/filetype/#supported-types

Rationale:
we need to determine the size of images.

@normanlorrain
Copy link
Owner Author

Current pytest suite shows where the error is.

@FlominatorTM
Copy link

I have at least one jpeg image, where elif imghdr.what(fname) returned None. Since there's a try-except clause with an empty return value anyway, it wouldn't hurt to add at least or imghdr.what(fname) == None: to that condition. I would assume that most images are jpeg, so it should cover most of the cases like mine.

elif imghdr.what(fname) == "jpeg":

On the other hand an implementation with guess = filetype.guess(fname) and then a switch using guess.extension might be more stable.

@normanlorrain
Copy link
Owner Author

I've replaced the code with a much simpler solution. Pytest suite passes. This is better anyway, using the already included PyMuPDF library, and the native imghdr module is deprecated.

Let me know if your jpeg still causes this code to stumble. Thanks!

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

No branches or pull requests

2 participants