-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added prepare_img function (stretch_and_squish, scale_and_centercrop,…
… scale_and_fill), added unit tests for prepare_img functions, added opencv-contrib-python requirement
- Loading branch information
1 parent
9b4bc07
commit 3a82a1e
Showing
6 changed files
with
96 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ coverage.xml | |
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
outputs/ | ||
|
||
# Translations | ||
*.mo | ||
|
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,3 @@ | ||
from tests import test_image | ||
|
||
test_image.test_prepares() |
Empty file.
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 | ||
from PIL.Image import Resampling | ||
|
||
from utils.image import prepare_img_scale_and_centercrop, prepare_img_scale_and_fill, prepare_img_stretch_and_squish | ||
|
||
def test_prepares(): | ||
target_size = 1344 | ||
resampling = Resampling.LANCZOS | ||
out_dir = "outputs/" | ||
|
||
os.makedirs(out_dir, exist_ok=True) | ||
|
||
for path in ["images/people_landscape.webp", "images/people_portrait.webp"]: | ||
basename, ext = os.path.splitext(os.path.basename(path)) | ||
img = Image.open(path) | ||
for name, func in [("stretch_and_squish", prepare_img_stretch_and_squish), ("scale_and_centercrop", prepare_img_scale_and_centercrop), ("scale_and_fill", prepare_img_scale_and_fill)]: | ||
if name == "scale_and_fill": | ||
for method in ["white", "gray", "black", "noise", "replicate", "reflect"]: | ||
ret = func(img, target_size, resampling, method) | ||
ret.save(f"{out_dir}/{basename}_{method}.webp", format='WebP', lossless=True, quality=0) | ||
else: | ||
ret = func(img, target_size, resampling) | ||
ret.save(f"{out_dir}/{basename}_{name}.webp", format='WebP', lossless=True, quality=0) |
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