Notice
		                                        
										
                                    
                                        
                                    
                                        Recent Posts
                                        
                                    
                                        
                                    
                                        Recent Comments
                                        
                                    
                                        
                                    
                                        Link
                                        
                                    
                                | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                                        Tags
                                        
                                    
                                        
                                    - SSL
 - JavaScript
 - SPC
 - Sqoop
 - 보조정렬
 - table
 - xPlatform
 - Spring
 - Express
 - Java
 - react
 - plugin
 - MSSQL
 - window
 - R
 - NPM
 - es6
 - Android
 - Kotlin
 - SQL
 - GIT
 - Eclipse
 - vaadin
 - 공정능력
 - Python
 - hadoop
 - tomcat
 - mapreduce
 - IntelliJ
 - mybatis
 
                                        Archives
                                        
                                    
                                        
                                    - Today
 
- Total
 
DBILITY
python 사진 이미지 다루기(image open, resize) 본문
반응형
    
    
    
  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
                        
                    
                
            
                
            
				
				
				
				
                
							