This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(screenshot): Save screenshot to 800x600px webp (#25)
- Loading branch information
Showing
4 changed files
with
170 additions
and
26 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from os import unlink | ||
|
||
from PIL import Image | ||
|
||
from ecoindex_scraper.models import ScreenShot | ||
|
||
|
||
def convert_screenshot_to_webp(screenshot: ScreenShot) -> None: | ||
image = Image.open(rf"{screenshot.__str__()}") | ||
width, height = image.size | ||
ratio = 800 / height if width > height else 600 / width | ||
|
||
image.convert("RGB").resize(size=(int(width * ratio), int(height * ratio))).save( | ||
rf"{screenshot.folder}/{screenshot.id}.webp", | ||
format="webp", | ||
) | ||
|
||
unlink(f"{screenshot.__str__()}") |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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