【问题标题】:how can i keep an image name when changing its extention更改扩展名时如何保留图像名称
【发布时间】:2022-07-18 23:28:26
【问题描述】:

我怎样才能得到没有根和路径的文件名。只有一个名称,以便我可以使用相同的原始名称保存要转换的图像?

import sys
import os,glob
from PIL import Image, ImageFilter


path = os.getcwd()

if not os.path.exists('converted'):
    save_to = os.makedirs('converted')


for i in glob.glob(f'{path}/*.jpg'):

    img = Image.open(i)

    img.save(???????)  ########  <---------?????????

    #i want to save the imege whith its original name,
    # but with a different extention, and i want to save it to a different folder then cwd

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    使用os.path.basename 获取不带路径的文件名。

    使用os.path.splitext 将文件名拆分为词干和后缀。

    【讨论】:

    • 但它也给了我路径......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 2017-03-12
    • 1970-01-01
    • 2011-07-29
    • 2018-10-05
    • 1970-01-01
    • 2016-05-27
    相关资源
    最近更新 更多