Skip to content

Commit

Permalink
Merge pull request #824 from girder/handle-pil-deprecations
Browse files Browse the repository at this point in the history
Handle PIL deprecations.
  • Loading branch information
manthey authored Apr 14, 2022
2 parents 1a65efc + 36cf1ab commit efb18cd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- Fix a range check for pixelmap annotations ([815](../../pull/815))
- Harden checking if a PIL Image can be read directly from a file pointer ([822](../../pull/822))

### Changes
- Handle PIL deprecations ([824](../../pull/824))

## Version 1.13.0

### Features
Expand Down
15 changes: 9 additions & 6 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,8 +1716,9 @@ def getRegion(self, format=(TILE_FORMAT_IMAGE, ), **kwargs):
if outWidth != regionWidth or outHeight != regionHeight:
image = _imageToPIL(image, mode).resize(
(outWidth, outHeight),
PIL.Image.BICUBIC if outWidth > regionWidth else
PIL.Image.LANCZOS)
getattr(PIL.Image, 'Resampling', PIL.Image).BICUBIC
if outWidth > regionWidth else
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS)
maxWidth = kwargs.get('output', {}).get('maxWidth')
maxHeight = kwargs.get('output', {}).get('maxHeight')
if kwargs.get('fill') and maxWidth and maxHeight:
Expand Down Expand Up @@ -2173,9 +2174,9 @@ def tileIterator(self, format=(TILE_FORMAT_NUMPY, ), resample=True,
Formats are members of (TILE_FORMAT_PIL, TILE_FORMAT_NUMPY,
TILE_FORMAT_IMAGE). If TILE_FORMAT_IMAGE, encoding must be
specified.
:param resample: If True or one of PIL.Image.NEAREST, LANCZOS,
BILINEAR, or BICUBIC to resample tiles that are not the target
output size. Tiles that are resampled will have additional
:param resample: If True or one of PIL.Image.Resampling.NEAREST,
LANCZOS, BILINEAR, or BICUBIC to resample tiles that are not the
target output size. Tiles that are resampled will have additional
dictionary entries of:
:scaled: the scaling factor that was applied (less than 1 is
Expand Down Expand Up @@ -2376,7 +2377,9 @@ def getAssociatedImage(self, imageKey, *args, **kwargs):
width, height, imageWidth, imageHeight)
image = image.resize(
(width, height),
PIL.Image.BICUBIC if width > imageWidth else PIL.Image.LANCZOS)
getattr(PIL.Image, 'Resampling', PIL.Image).BICUBIC
if width > imageWidth else
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS)
return _encodeImage(image, **kwargs)

def getPixel(self, includeTileRecord=False, **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion large_image/tilesource/tiledict.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def __getitem__(self, key, *args, **kwargs):
pilData.size[1] / self.requestedScale))
pilData = tileData = pilData.resize(
(self['width'], self['height']),
resample=PIL.Image.LANCZOS if self.resample is True else self.resample)
resample=getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS
if self.resample is True else self.resample)

tileFormat = (TILE_FORMAT_PIL if isinstance(tileData, PIL.Image.Image)
else (TILE_FORMAT_NUMPY if isinstance(tileData, numpy.ndarray)
Expand Down
2 changes: 1 addition & 1 deletion sources/openslide/large_image_source_openslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs):
# Always scale to the svs level 0 tile size.
if svslevel['scale'] != 1:
tile = tile.resize((self.tileWidth, self.tileHeight),
PIL.Image.LANCZOS)
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS)
return self._outputTile(tile, TILE_FORMAT_PIL, x, y, z, pilImageAllowed,
numpyAllowed, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion sources/tiff/large_image_source_tiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def getTileFromEmptyDirectory(self, x, y, z, **kwargs):
tile.paste(subtile, (newX * self.tileWidth,
newY * self.tileHeight))
return tile.resize((self.tileWidth, self.tileHeight),
PIL.Image.LANCZOS)
getattr(PIL.Image, 'Resampling', PIL.Image).LANCZOS)

def getPreferredLevel(self, level):
"""
Expand Down

0 comments on commit efb18cd

Please sign in to comment.