pthon批量更改图片md5

import os
import hashlib
import time
# 这是一个示例 Python 脚本。

# 按 Shift+F10 执行或将其替换为您的代码。
# 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。

def showmd5(dirpath):
    filenames = os.listdir(dirpath)
    for filename in filenames[:]:
        filepath = dirpath + '/' + filename
        if filepath.endswith('.png') or filepath.endswith('.jpg') or filepath.endswith('jpeg'):
            fd = open(filepath, "rb")
            f = fd.read()
            pmd5 = hashlib.md5(f)
            print(filename, pmd5.hexdigest())

def rmd5():
    dirpath = input("请输入图片路径:")
    writefile = int(time.time() * 1000)
    filenames = os.walk(dirpath)
    for root, dirs, files in filenames:
        for file in files:
            file = os.path.join(root, file)
            if file.endswith('.png') or file.endswith('.jpg') or file.endswith('jpeg'):
                with open(file, "rb") as fd:
                    f = fd.read()
                    pmd5 = hashlib.md5(f)
                    ff = file+" "+pmd5.hexdigest()

                with open(file, "a") as f:
                    f.write(str(writefile))

                with open(file, "rb") as fd:
                    f = fd.read()
                    pmd5 = hashlib.md5(f)
                    print(ff+" 改后:"+pmd5.hexdigest())
    rmd5()

# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
    rmd5()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

boyxgb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值