• 借用GUI批量处理图片


    import os
    import tkinter as tk
    
    from PIL import Image
    
    """
    将python.py文件打包为exe文件
    pip install pyinstaller
    pyinstaller -F photo_process_gui.py
    """
    dpi = 96
    # 1 inch=2.54cm
    width = 25.4 / 2.54
    height = 19.05 / 2.54
    width_pixel = width * dpi
    height_pixel = height * dpi
    
    window = tk.Tk()
    
    entry = tk.Entry(window, width=20)
    entry.pack()
    
    entry2 = tk.Entry(window, width=20)
    entry2.pack()
    
    
    # 修改图片尺寸
    def resize_image(filein, fileout, w, h):
        img = Image.open(filein)
        # 调整大小
        out=img.resize((w, h))
        out.save(fileout)
    
    
    # 从GUI获取输入输出文件夹
    def change_state():
        in_path = entry.get()  # 调用get()方法,将Entry中的内容获取出来
        out_path = entry2.get()
        print(in_path, out_path)
        files = os.listdir(in_path)
        for file in files:
            resize_image(os.path.join(in_path, file), os.path.join(out_path, file), width_pixel, height_pixel)
    
    
    button = tk.Button(window, text='执行', command=change_state).pack()
    window.mainloop()
  • 相关阅读:
    elementUI form select验证问题
    Echart--基本属性
    Echart--饼状图
    Echart--折线图
    Echart--多个柱形图
    Echart--单个柱形图
    Echart--圆型图
    构析函数和构造函数
    心情
    图片
  • 原文地址:https://www.cnblogs.com/wangbin2188/p/13851216.html
Copyright © 2020-2023  润新知