--- a/pybadges/__init__.py
+++ b/pybadges/__init__.py
@@ -30,7 +30,6 @@
 """
 
 import base64
-import imghdr
 import mimetypes
 from typing import Optional
 import urllib.parse
@@ -71,6 +70,21 @@
     'inactive': '#9f9f9f',
 }
 
+def imghdr_what(data: bytes) -> Optional[str]:
+    """Replacement for the deprecated imghdr module"""
+    if len(data) <= 32:
+        return None
+    header = data[0:32]
+    if header[6:10] in (b'JFIF', b'Exif'):
+        return 'jpeg'
+    elif header[:4] == b'\xff\xd8\xff\xdb':
+        return 'jpeg'
+    elif header.startswith(b'\211PNG\r\n\032\n'):
+        return 'png'
+    elif header[:6] in (b'GIF87a', b'GIF89a'):
+        return 'gif'
+    else:
+        return None
 
 def _remove_blanks(node):
     for x in node.childNodes:
@@ -102,7 +116,7 @@
     else:
         with open(url, 'rb') as f:
             image_data = f.read()
-        image_type = imghdr.what(None, image_data)
+        image_type = imghdr_what(image_data)
         if not image_type:
             mime_type, _ = mimetypes.guess_type(url, strict=False)
             if not mime_type:
