0

как сохранить обработанные файлы по новому пути: есть код:

import os
from PIL import Image

    dir = os.path.abspath('/Path_to_files')
    resize = os.path.abspath('/Path_to_new_files')
    
    for f in os.scandir(dir):
        if f.is_file() and f.path.split('.')[-1].lower() == 'jpg':
            image = Image.open(f.path)
            image.save()

Как в цикле сохранить все файлы в каталог "resize", без изменения имен файлов?

1
  • image.save( f'{os.path.join(outDir, outFileName)}.png', 'PNG', compress_level=self.compressLevel) 7 окт 2022 в 3:07

1 ответ 1

0

Ларчик все-же просто открывался:

import os
from PIL import Image

dir = os.path.abspath('/path_to_files')
resize = os.path.abspath('/path_to_new_files/{}') 

for f in os.scandir(dir):
    if f.is_file() and f.path.split('.')[-1].lower() == 'jpg':
        image = Image.open(f.path)
        image.save(resize.format(f.name))
0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.