summarylogtreecommitdiffstats
path: root/imghdr.patch
blob: 598a025d6a618b5ade2a9fb4e8e5dd35094bf91f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
diff --unified --recursive --text a/lib/autokey/scripting/highlevel.py b/lib/autokey/scripting/highlevel.py
--- a/lib/autokey/scripting/highlevel.py	2022-06-05 17:28:30.000000000 -0600
+++ b/lib/autokey/scripting/highlevel.py	2024-12-29 10:49:03.302436869 -0700
@@ -6,7 +6,7 @@
 import os
 import subprocess
 import tempfile
-import imghdr
+import magic
 import struct
 
 
@@ -72,10 +72,11 @@
     @returns: (width, height).
     @raise Exception: Raised if the file is not a png
     """
-    if not imghdr.what(filepath) == 'png':
-        raise Exception("not PNG")
-    head = open(filepath, 'rb').read(24)
-    return struct.unpack('!II', head[16:24])
+    with open(filepath, 'rb') as f:
+        if not magic.detect_from_fobj(f).mime_type == "image/png":
+            raise Exception("not PNG")
+        head = f.read(24)
+        return struct.unpack('!II', head[16:24])
 
 
 def mouse_move(x: int, y: int, display: str=''):