-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split imagetools from module to package
- Loading branch information
Showing
14 changed files
with
1,529 additions
and
1,404 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from .exif import read_exif | ||
from .image_info import get_image_info | ||
from .thumbnail import make_image_thumbnail | ||
from .thumbnail import Thumbnail | ||
from .thumbnail import ThumbnailMode | ||
|
||
__all__ = [ | ||
"get_image_info", | ||
"make_image_thumbnail", | ||
"read_exif", | ||
"Thumbnail", | ||
"ThumbnailMode", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Compatibility with various versions of Pillow.""" | ||
from __future__ import annotations | ||
|
||
from enum import IntEnum | ||
from types import ModuleType | ||
from types import SimpleNamespace | ||
from typing import Mapping | ||
|
||
import PIL.ExifTags | ||
|
||
__all__ = ["ExifTags", "UnidentifiedImageError"] | ||
|
||
PILLOW_VERSION_INFO = tuple(map(int, PIL.__version__.split("."))) | ||
|
||
if PILLOW_VERSION_INFO >= (9, 4): | ||
ExifTags: ModuleType | SimpleNamespace = PIL.ExifTags | ||
else: | ||
# Pillow < 9.4 does not provide the PIL.ExifTags.{Base,GPS,IFD} enums. Here we provide | ||
# and ExifTags namespace which has them. | ||
|
||
def _reverse_map(mapping: Mapping[int, str]) -> dict[str, int]: | ||
return dict(map(reversed, mapping.items())) # type: ignore[arg-type] | ||
|
||
ExifTags = SimpleNamespace( | ||
Base=IntEnum("Base", _reverse_map(PIL.ExifTags.TAGS)), | ||
GPS=IntEnum("GPS", _reverse_map(PIL.ExifTags.GPSTAGS)), | ||
IFD=IntEnum("IFD", [("Exif", 34665), ("GPSInfo", 34853)]), | ||
TAGS=PIL.ExifTags.TAGS, | ||
GPSTAGS=PIL.ExifTags.GPSTAGS, | ||
) | ||
|
||
|
||
# UnidentifiedImageError only exists in Pillow >= 7.0.0 | ||
UnidentifiedImageError = getattr(PIL, "UnidentifiedImageError", OSError) |
Oops, something went wrong.