프로그래밍 언어/<Python>

[파이썬] 이미지 크기 변환 배치

소혼 2011. 6. 12. 23:01
반응형
아이폰용 이미지를 안드로이드용으로 바꾸기 위해 예섬에게 부탁했더니..

스크립트를 만들어서 줬다 -_-;
왜 내가 만들 생각을 못했을까? ;;

#!/user/bin/python

import os
import sys 
from PIL import Image

def walk(org_dir_path, new_dir_path):
    print "walk" + org_dir_path + " / " + new_dir_path
    for root, dirs, files in os.walk(org_dir_path):
        for name in files : 
            img_path = os.path.join(root, name)
            print 'resized file = ' + img_path
            img = Image.open(img_path)
            img_height, img_width =  img.size
            #print str(img_height) + 'X' + str(img_width)
            resize = (img_height /640.0 * 480, img_width /640.0 * 480)
            #print str(resize[0]) + 'X' + str(resize[1]) 
            changeSize(img, os.path.join(new_dir_path, name), resize)
                 
        # end of for
    # end of for
# end of function 

def changeSize(img, new_file_path, resize):
    #print str(resize[0]) + 'X' + str(resize[1]) 
    resized_img = img.resize(resize)
    resized_img.save(new_file_path)
# end of function 

if __name__ == "__main__" : 
    walk(sys.argv[1], sys.argv[2])
# end of main 
반응형

'프로그래밍 언어 > <Python>' 카테고리의 다른 글

py2exe with PMW  (0) 2010.12.28
py2exe  (0) 2010.12.28
[python]XML 처리  (0) 2010.10.12
[파이썬] CSV2SQL ver 0.1  (0) 2010.08.27
[python] Windows에서 커맨드창 하나 더 띄우기  (0) 2010.08.24