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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
Origin: https://gitlab.gnome.org/GNOME/ocrfeeder/-/merge_requests/17
From: Balló György <ballogyor@gmail.com>
Date: Wed, 22 May 2024 15:02:45 +0000
Subject: Don't use deprecated imghdr module
The imghdr module is removed in Python 3.13.
Closes: https://gitlab.gnome.org/GNOME/ocrfeeder/-/issues/95
---
src/ocrfeeder/util/graphics.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/ocrfeeder/util/graphics.py b/src/ocrfeeder/util/graphics.py
index 851cfe3..2ad2511 100644
--- a/src/ocrfeeder/util/graphics.py
+++ b/src/ocrfeeder/util/graphics.py
@@ -22,7 +22,6 @@ from .log import debug
from PIL import Image
from gi.repository import GdkPixbuf
import math
-import imghdr
import os
def getContainerRectangle(points_list):
@@ -183,14 +182,18 @@ def getImageRotated(image, angle):
def convertMultiImage(image_path, temp_dir):
converted_paths = []
- if imghdr.what(image_path) != 'tiff':
+ try:
+ image = Image.open(image_path)
+ except Exception:
+ return []
+
+ if image.format != "TIFF":
return [image_path]
debug('Checking for multiple images in TIFF')
i = 0
base_name = os.path.basename(image_path)
name, extension = os.path.splitext(base_name)
- image = Image.open(image_path)
try:
while True:
image.seek(i)
|