Closed cclauss closed 2 months ago
Oddly I was thinking of this the other day, I've not used imghdr
does it literally just return an extension?
% python3.12 -c"import imghdr ; print(imghdr.what(None, b'\xff\xd8\xff\xdb'))"
<string>:1: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13
jpeg
Source code: https://github.com/python/cpython/blob/3.12/Lib/imghdr.py
% python3.12
>>> import imghdr
<stdin>:1: DeprecationWarning: 'imghdr' is deprecated and slated for removal in Python 3.13
>>> ", ".join(sorted(test_func.__name__[5:] for test_func in imghdr.tests))
'bmp, exr, gif, jpeg, pbm, pgm, png, ppm, rast, rgb, tiff, webp, xbm'
That's super basic, at a guess we could go with a very basic shim:
import puremagic as imghdr
Add a def for .what
and just return the highest confidence extension minus the .
from the database. That would provide a very basic drop-in replacment with the added power of the larger database. Folks could then transition to a proper PureMagic implementation.
Released in https://github.com/cdgriffith/puremagic/releases/tag/1.24 thanks!
Given the discussion in #67 about
imghdr
being removed from the Python Standard Library, it might be quite helpful to have a drop-in replacement forimghdr.what()
. It would provide a smooth transition to Py3.13 if developers could confidently replace all instances ofimghdr.what()
withpuremagic.what()
-- same args, same results.67
68