from PIL import Image
import glob, os
directory = "your path "
for infile in glob.glob("*.bmp"):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
im.save(file + ".ppm", "PPM")
I was able to convert only one image, can you please help to get entire image converted to ppm format
答案 0 :(得分:1)
只要我在感兴趣的目录中,您的代码就可以为我工作。您的代码未使用directory
信息,因此,如果您在其他目录中,则可能找不到带有.ppm
的任何glob
文件,因此是空操作。我将修改您的代码,如下所示:
from PIL import Image
import glob, os
target_directory = "/path/to/folder"
for infile in glob.glob(os.path.join(target_directory, "*.bmp")):
file, ext = os.path.splitext(infile)
im = Image.open(infile)
im.save(file + ".ppm", "PPM")