-
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.
- Loading branch information
1 parent
658f505
commit c219717
Showing
1 changed file
with
47 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import glob | ||
from os import getcwd | ||
from os.path import join | ||
|
||
from anshitsu.retouch import Retouch | ||
|
||
from PIL import Image | ||
|
||
|
||
def grayscaling(path: str): | ||
""" | ||
grayscaling 画像をグレースケール化する | ||
Args: | ||
path (str): ファイルパス | ||
Returns: | ||
Image: 与えられたパスの画像をグレースケール化したもの | ||
""" | ||
image = Image.open(path) | ||
retouch = Retouch(image, grayscale=True) | ||
gray_image = retouch.process() | ||
return gray_image | ||
|
||
|
||
def bundle_grayscaling(dir: str): | ||
""" | ||
bundle_grayscaling 指定されたディレクトリ内のGIF、PNG、JPEGファイルをグレースケール化する | ||
Args: | ||
dir (str): 画像を格納したディレクトリ | ||
""" | ||
path_list: list[str] = [] | ||
for ext in ('*.gif', '*.png', '*.jpg', '*.jpeg'): | ||
path_list.extend(glob.glob(join(dir, ext))) | ||
|
||
for i in path_list: | ||
print(i) | ||
img = grayscaling(i) | ||
img.save(i) | ||
print(i) | ||
return | ||
|
||
|
||
image_path = getcwd() + "/images" | ||
print(image_path) | ||
bundle_grayscaling(image_path) |