Skip to content

Commit

Permalink
Create grayscaling.py
Browse files Browse the repository at this point in the history
  • Loading branch information
huideyeren authored Dec 4, 2023
1 parent 658f505 commit c219717
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions grayscaling.py
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)

0 comments on commit c219717

Please sign in to comment.