From 61b3e0bc48862e0a680ec455dc91d285578da141 Mon Sep 17 00:00:00 2001 From: Arne de Laat Date: Wed, 30 Aug 2023 21:55:37 +0200 Subject: [PATCH 1/3] Add module to create a thumbnail from an image Make it easy to generate a thumbnail for a movie by resizing one of the frames into a thumbnail. --- pyproject.toml | 1 + time_lapse/thumbnail.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 time_lapse/thumbnail.py diff --git a/pyproject.toml b/pyproject.toml index f15d336..b53b2fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ classifiers = [ dependencies = [ 'exifreader==0.1.1', 'ffmpeg-python==0.2.0', + 'pillow==10.0.0', ] [project.optional-dependencies] diff --git a/time_lapse/thumbnail.py b/time_lapse/thumbnail.py new file mode 100644 index 0000000..8b1b571 --- /dev/null +++ b/time_lapse/thumbnail.py @@ -0,0 +1,21 @@ +import pathlib +import shutil + +from PIL import Image + + +def create_thumbnail( + name: str, + poster_path: pathlib.Path, +) -> None: + target_path = pathlib.Path() / f'{name}.png' + thumbnail_path = target_path.parent / f'{name}@2x.png' + with Image.open(poster_path) as image: + image.resize( + size=(180, 120), + resample=Image.LANCZOS, + ).save( + thumbnail_path, + compress=False, + ) + shutil.copy(poster_path, target_path) From 54e0b58847a859bbf137229c04d5290c2ac64804 Mon Sep 17 00:00:00 2001 From: Arne de Laat Date: Fri, 1 Sep 2023 14:48:03 +0200 Subject: [PATCH 2/3] Make thumbnail dimensions keyword arguments --- time_lapse/thumbnail.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/time_lapse/thumbnail.py b/time_lapse/thumbnail.py index 8b1b571..0e0bea4 100644 --- a/time_lapse/thumbnail.py +++ b/time_lapse/thumbnail.py @@ -7,12 +7,14 @@ def create_thumbnail( name: str, poster_path: pathlib.Path, + width: int = 180, + height: int = 120, ) -> None: target_path = pathlib.Path() / f'{name}.png' thumbnail_path = target_path.parent / f'{name}@2x.png' with Image.open(poster_path) as image: image.resize( - size=(180, 120), + size=(width, height), resample=Image.LANCZOS, ).save( thumbnail_path, From ae329649bbfa57f0093ffb3847a388b528aad353 Mon Sep 17 00:00:00 2001 From: Arne de Laat Date: Sun, 10 Sep 2023 14:13:19 +0200 Subject: [PATCH 3/3] Keep original suffix for poster --- time_lapse/thumbnail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/time_lapse/thumbnail.py b/time_lapse/thumbnail.py index 0e0bea4..f602f9a 100644 --- a/time_lapse/thumbnail.py +++ b/time_lapse/thumbnail.py @@ -10,7 +10,7 @@ def create_thumbnail( width: int = 180, height: int = 120, ) -> None: - target_path = pathlib.Path() / f'{name}.png' + target_path = pathlib.Path() / f'{name}{poster_path.suffix}' thumbnail_path = target_path.parent / f'{name}@2x.png' with Image.open(poster_path) as image: image.resize(