Skip to content

Commit

Permalink
fix PIL deprecation and cleanup PIL code
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Aug 19, 2022
1 parent 50cb1db commit 829126f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
14 changes: 5 additions & 9 deletions src/Products/PlonePAS/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from PIL import Image


PROJECTNAME = "PlonePAS"
GLOBALS = globals()

Expand All @@ -9,15 +12,8 @@
}

# Settings for member image resize quality
HAS_PIL = True
try:
from PIL import Image

PIL_SCALING_ALGO = Image.ANTIALIAS
except ImportError:
PIL_SCALING_ALGO = None
HAS_PIL = False

HAS_PIL = True # remove in Version 8
PIL_SCALING_ALGO = Image.Resampling.LANCZOS
PIL_QUALITY = 88
MEMBER_IMAGE_SCALE = (75, 100)
IMAGE_SCALE_PARAMS = {
Expand Down
9 changes: 1 addition & 8 deletions src/Products/PlonePAS/tools/membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from Products.CMFCore.permissions import View
from Products.CMFCore.utils import _checkPermission
from Products.CMFCore.utils import getToolByName
from Products.PlonePAS.config import HAS_PIL
from Products.PlonePAS.events import UserInitialLoginInEvent
from Products.PlonePAS.events import UserLoggedInEvent
from Products.PlonePAS.events import UserLoggedOutEvent
Expand All @@ -38,6 +37,7 @@
from zope.interface import implementer

import logging
import PIL
import transaction


Expand Down Expand Up @@ -764,14 +764,7 @@ def getBadMembers(self):
portrait_data = portrait.data
if not portrait_data:
continue
if not HAS_PIL:
raise RuntimeError(
"No Python Imaging Libraries (PIL) found. "
"Unable to validate profile image. "
)
try:
import PIL

PIL.Image.open(BytesIO(portrait_data))
except ConflictError:
pass
Expand Down

0 comments on commit 829126f

Please sign in to comment.