forked from invoke-ai/InvokeAI
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nodes): add thumbnail generation to DiskImageStorage
- Loading branch information
1 parent
18cddd7
commit aed9ece
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,25 @@ | ||
import os | ||
from PIL import Image | ||
|
||
|
||
def save_thumbnail( | ||
image: Image.Image, | ||
filename: str, | ||
path: str, | ||
size: int = 256, | ||
) -> str: | ||
""" | ||
Saves a thumbnail of an image, returning its path. | ||
""" | ||
base_filename = os.path.splitext(filename)[0] | ||
thumbnail_path = os.path.join(path, base_filename + ".webp") | ||
|
||
if os.path.exists(thumbnail_path): | ||
return thumbnail_path | ||
|
||
image_copy = image.copy() | ||
image_copy.thumbnail(size=(size, size)) | ||
|
||
image_copy.save(thumbnail_path, "WEBP") | ||
|
||
return thumbnail_path |