본문 바로가기
Programming/python

[python] 파이썬으로 썸네일 이미지 만들기

by x-coder 2023. 9. 16.

Hello. { #Somebody }

썸네일(thumbnail) 이미지 만들기

 

간단하게 파이썬으로 썸네일 이미지  만들 수 있는 방법에 대해서 기록합니다.

 

pillow 모듈 설치
pip install pillow

 

소스 코드
import os
from PIL import Image

def main():
    size = (512, 512)
    
    imageFile = "sample_image.jpg"
    
    filePath = ("%s_resized.%s" % (os.path.splitext(imageFile)[0], "jpg"))
    
    try:
        image = Image.open(imageFile)
        image.thumbnail(size)
        image.save(filePath, 'JPEG', quality=100)
        
    except IOError:
        print("Failed to create thumbnail of %s" % imageFile)
        
if __name__ == '__main__':
    main()

 

 

 

Python is simple

Bye. { #Somebody }