0
Python Imagingライブラリを使用して画像のサイズを変更するためのスクリプトを作成しました。コードは正常に動作していますが、スクリプトは.pyスクリプトファイルも読み込んでいます。どうすればそれを避けることができますか?Pythonの画像コードのサイズ変更もスクリプトファイルを読む
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
ありがとうございました。この投稿に関連することをもう1つ質問するか、新しい質問をしなければなりませんか? –
おそらく新しい質問が良いでしょう。 –