尝试通过 Python 脚本调整某些图像的大小(仅宽度)。这是一个 Python 脚本:
# -*- coding: utf-8 -*-
import subprocess
import os
# New width
new_width = '200'
# Create for converted images
create_directory_out = subprocess.run(['mkdir', '-p', './Result'])
# Directory with started images
directory_source = 'Source'
# Directory with converted images
directory_out = 'Result'
# get list of started images to variable files
files = os.listdir(directory_source)
# Filtre by mask .jpg to variable images
images = filter(lambda x: x.endswith('.jpg'), files)
img_list = list(images)
# Loop of convert images by sips
for file_name in img_list:
print(file_name)
subprocess.run(['sips', '--resampleWidth', 'new_width', '--out', './directory_out/file_name', './directory_source/file_name', ])
我收到一个错误:
face-04.jpg
Warning: ./directory_source/file_name not a valid file - skipping
Error 4: no file was specified
Try 'sips --help' for help using this tool
face-04.jpg
但是终端中的 sips 命令正在工作:
sips --resampleWidth 200 --out ./Result/face-04.jpg ./Source/face-04.jpg
还有什么问题?
在此先感谢您的帮助。