0
파이썬 이미징 라이브러리를 사용하여 이미지 크기를 조정하기위한 스크립트를 작성했습니다. 코드는 잘 작동하지만 스크립트는 .py 스크립트 파일을 읽습니다. 어떻게 피할 수 있습니까?크기 조정 파이썬의 이미지 코드도 스크립트 파일을 읽는 중
import os
import sys
import PIL
import PIL as pillow
from PIL import Image
from resizeimage import resizeimage
opts, args = getopt.getopt(sys.argv[1:], 'd:w:h:')
filepath = r'C://python27//test'
saved = 'C://python27//test2'
basewidth = 4193
for opt, arg in opts:
if opt == '-d':
filepath = arg
if opt == '-w':
basewidth = int(arg)
if basewidth == -1 or filepath == '':
print('Invalid command line arguments. -d [directory] ' \
'-w [width] are required')
exit()
for image in os.listdir(filepath):
print('Resizing image ' + image)
name,ext = os.path.splitext(image)
if ext.lower() in [".png", ".jpg", ".bmp"]:
img = Image.open(image)
width = (basewidth/float(img.size[0]))
height = int((float(img.size[1]) * float(width)))
img = img.resize((basewidth, height), PIL.Image.ANTIALIAS)
img = resizeimage.resize('crop', img, [3000, 2800])
img.save(os.path.join(saved, 'resized-' + image))
출력 : Resizing image 852A9961.JPG Resizing image pc1.PNG Resizing image try13.py
대단히 감사합니다. 이 게시물과 관련된 한 가지 더 물어봐도 될까요 아니면 새로운 질문을해야합니까? –
아마도 새로운 질문 일 것입니다. –