Skip to content

Commit bf8298c

Browse files
committed
allow pil image as input
1 parent 34d3920 commit bf8298c

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

thumbhash/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from thumbhash.decode import thumbhash_to_image as thumbhash_to_image
2-
from thumbhash.encode import image_to_thumbhash as image_to_thumbhash
2+
from thumbhash.encode import image_to_thumbhash as image_to_thumbhash, pil_image_to_thumbhash
33

4-
__all__ = ["image_to_thumbhash", "thumbhash_to_image"]
4+
__all__ = ["image_to_thumbhash", "thumbhash_to_image", "pil_image_to_thumbhash"]

thumbhash/encode.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
def image_to_thumbhash(
1313
image: Union[str, bytes, Path, BinaryIO],
1414
) -> str:
15-
m_image = exif_transpose(Image.open(image)).convert("RGBA")
15+
return pil_image_to_thumbhash(Image.open(image))
16+
17+
18+
def pil_image_to_thumbhash(image: Image.Image) -> str:
19+
m_image = exif_transpose(image).convert("RGBA")
1620

1721
m_image.thumbnail((100, 100))
1822

0 commit comments

Comments
 (0)