首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python中将JFIF文件转换为JPEG

在python中将JFIF文件转换为JPEG
EN

Stack Overflow用户
提问于 2022-05-10 17:53:50
回答 1查看 656关注 0票数 1

我有一个文件夹与JFIF照片,我需要将它们全部转换成JPEG格式,我认为问题来自我的if语句,因为文件夹中有其他照片不需要转换或for循环。谢谢

代码语言:javascript
复制
from PIL import Image
import os

root = r"(my computer path to the folder)"

count = 0
for dirs, subdir, files in os.walk(root):
    for file in files:
        lastChar = file[-1:]
        if(lastChar == 'f'):
            img = Image.open(file)
            #file ends in .jfif, remove 4 characters
            fileName = file[:-4]
            #add jpg and save
            img.save(fileName + "jpg")

我现在正在收到这个错误,FileNotFoundError: Errno 2没有这样的文件或目录:'IMG_4242_1615254307.jfif‘

EN

回答 1

Stack Overflow用户

发布于 2022-05-20 09:45:11

代码语言:javascript
复制
from PIL import Image
import os

root = r"my computer path to the folder"
print(root)
count = 0
for dirs, subdir, files in os.walk(root):
    for file in files:
        lastChar = file[-4:]
        if(lastChar == 'jfif'):
            img = Image.open(root+'\\'+file)
            #file ends in .jfif, remove 4 characters
            fileName = file[:-4]
            print(fileName)
            #add jpg and save
            img.save(root+'\\'+fileName + "jpg")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72190966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档