前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >关于手机拍摄的图片在处理过程中出现问题的解决方法

关于手机拍摄的图片在处理过程中出现问题的解决方法

作者头像
爱喝水的木子
发布2022-01-12 14:53:22
1750
发布2022-01-12 14:53:22
举报
文章被收录于专栏:爱喝水的木子
代码语言:javascript
复制
from PIL import Image
import os


# 图片旋转
def image_route(in_file, out_file):
    img = Image.open(in_file)
    dict_exif = img.getexif()
    try:
        res = dict_exif[274]
        if res == 1:
            img = img.rotate(0, expand=True)
        elif res == 8:
            print("向右", in_file)
            img = img.rotate(90, expand=True)
        elif res == 6:
            print("向左", in_file)
            img = img.rotate(-90, expand=True)
        elif res == 3:
            print("翻转", in_file)
            img = img.rotate(180, expand=True)
        else:
            print(res, "不正常", in_file)
            img = img.rotate(0, expand=True)
        img.save(out_file)
    except:
        print("error:", in_file)
        img = img.rotate(0, expand=True)
        img.save(os.path.join(_save, i))


if __name__ == '__main__':
    # 要调整的路径
    path = r"C:\Users\***\Desktop\30\1"
    # 调整之后保存的路径
    _save = r"C:\Users\***\Desktop\30\2"
    for i in os.listdir(path):
        in_file = os.path.join(path, i)
        out_file = os.path.join(_save, i)
        image_route(in_file, out_file)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-03-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档