Skip to content

Commit 4a021eb

Browse files
committed
Fix compatibility with PIL version 12
PIL version 12 removed `PIL.Image.isImageType()` (see python-pillow/Pillow#9053). Closes #41.
1 parent 438ca77 commit 4a021eb

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

Changelog.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
ChangeLog
22
=========
33

4-
3.1 (unreleased)
4+
4.0 (unreleased)
55
----------------
66

7-
- Nothing changed yet.
7+
- Fix support of PIL (Pillow) 12.
88

99

1010
3.0 (2020-01-02)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = zbarlight
3-
version = 3.1.dev0
3+
version = 4.0.dev0
44
author = Polyconseil
55
author_email = [email protected]
66
url = https://github.com/Polyconseil/zbarlight

src/zbarlight/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pkg_resources
44
from PIL import Image
55

6+
from . import compat
67
from ._zbarlight import Symbologies
78
from ._zbarlight import zbar_code_scanner
89

@@ -65,7 +66,7 @@ def scan_codes(code_types, image):
6566
raise UnknownSymbologieError('Unknown Symbologies: %s' % bad_code_types)
6667

6768
# Convert the image to be used by c-extension
68-
if not Image.isImageType(image):
69+
if not compat.is_image(image):
6970
raise RuntimeError('Bad or unknown image format')
7071
converted_image = image.convert('L') # Convert image to gray scale (8 bits per pixel).
7172
raw = converted_image.tobytes() # Get image data.

src/zbarlight/compat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# FIXME: this could probably be removed by properly typing
2+
# `zbarlight.scan_codes()`.
3+
try:
4+
from PIL import Image
5+
is_image = Image.isImageType
6+
except AttributeError:
7+
# Image.isImageType has been removed from PIL 12.0
8+
def is_image(im):
9+
return isinstance(im, Image.Image)

0 commit comments

Comments
 (0)