微信聊天记录长图切割

将微信聊天记录长截图进行切割,除第一张切图外,其余切图包含上张切图的后几句聊天记录,支持2种格式,单张或双张切图。
demo

依赖

  • pillow
  • tkinter

运行

python main.py

运行界面

操作说明

选择长截图所在文件夹,点击运行即可。
程序会遍历所选文件夹下的所有图片,对其进行截图,结果保存在所选文件夹下的所选图片同名的文件夹下,按顺序进行编号。

主要代码

def splitPicture(file_name: str, width_dt: int = 10):
    config_file = "config.json"
    if os.path.exists(config_file):
        config_json = getConfigData(config_file)
    else:
        config_json = {"图片高度": 2400, "重复高度": 200}
        with open(config_file, "w", encoding="utf-8") as f:
            f.write(json.dumps(config_json, ensure_ascii=False))
    pic_height = config_json["图片高度"]
    idt_height = config_json["重复高度"]

    path, text = os.path.splitext(file_name)
    _, name = os.path.split(path)
    if not os.path.exists(path):
        os.mkdir(path)
    im = Image.open(file_name)
    image_width, image_height = im.size

    i = 1
    upper = 0
    to_image = None
    while upper < image_height:
        if upper > idt_height:
            upper -= idt_height
        bottom = upper + pic_height
        if bottom > image_height:
            bottom = image_height
        region = im.crop((0, upper, image_width, bottom))
        region.save(os.path.join(path, f"{name}_{i:02d}{text}"))

        if to_image is None:
            to_image = Image.new(
                "RGB", (image_width * 2 + width_dt, pic_height), "white"
            )
            to_image.paste(region, (0, 0))
        else:
            to_image.paste(region, (image_width + width_dt, 0))
            to_image.save(os.path.join(path, f"_{name}_{(i-1):02d}{text}"))
            to_image = Image.new(
                "RGB", (image_width * 2 + width_dt, pic_height), "white"
            )
            to_image.paste(region, (0, 0))

        upper = bottom
        i += 1
    return None

配置

参见config.json

{
    "图片高度": 2400,
    "重复高度": 200
}

打包

pyinstaller -F -w -i .\favicon.ico -n 切图 .\main.py -i .\favicon.ico -n 切图 .\main.py

github

https://github.com/chenwr727/wechat-chat-record-screenshot

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值