DBILITY

python 사진 이미지 다루기(image open, resize) 본문

python

python 사진 이미지 다루기(image open, resize)

DBILITY 2021. 8. 19. 16:39
반응형

pip install pillow 또는 나는 intellij를 사용하니 Python Packages Window에서 설치했음.

사용법은 아래 공식사이트를 참고하자.

 

Pillow

Pillow is the friendly PIL fork by Alex Clark and Contributors. PIL is the Python Imaging Library by Fredrik Lundh and Contributors. Pillow for enterprise is available via the Tidelift Subscription...

pillow.readthedocs.io

import os
import shutil
from PIL import Image

target_directory = r'.\images'
# execution directory
print(os.getcwd())

os.chdir(target_directory)
# change directory
print(os.getcwd())

image_list: list = os.listdir(r'.\\')
for image_name in image_list:
    print(image_name)
    img = Image.open(image_name)
    # 비율유지 안됨
    # resize_img = img.resize((300, 500))
    # resize_img.save(f'resize_{image_name}')

    # 비율유지 됨
    img.thumbnail((300, 500))
    img.save(f'resize_{image_name}', quality=90)
    # 공식사이트를 참고하자.
    # https://pillow.readthedocs.io/
반응형

'python' 카테고리의 다른 글

python regular expression ( 정규 표현식 )  (0) 2021.08.20
python 메일보내기  (0) 2021.08.19
python requests 헤더(header), 쿠키(cookie) 추가하기  (0) 2021.08.19
python class  (0) 2021.08.19
python file rename, copy etc.  (0) 2021.08.19
Comments