python:批量压缩图片质量

image.png

image.png
#compress_image
#click-> dosomething

from tkinter import *
from tkinter.filedialog import *
from  PIL import Image as Img

info = {'path':[]}

def make_app():
    app = Tk()
    #标签
    Label(app,text='图片压缩小工具',font=('Hack',20,'bold')).pack()
    Listbox(app,name='lbox',bg='#f2f2f2').pack(fill=BOTH,expand =True)
    Button(app,text='Open',command=ui_getdata).pack()
    Button(app,text='compress',command=compress).pack()
    app.geometry('300x400')
    return app

def ui_getdata():
    f_name=askopenfilenames()
    lbox = app.children['lbox']
    info['path'] = f_name
    if info['path']:
        for name in f_name :
            lbox.insert(END,name.split('/')[-1])

def compress():
    for f_path in info['path']:
        #输出路径
        output = 'F:/output/'
        #图片的文件名
        name = f_path.split('/')[-1]
        # 打开图片
        image = Img.open(f_path)
        # 图片另存到output文件夹中,图片质量压缩到60%
        image.save(output+'C_'+name, quality=60)

app = make_app()

mainloop()

你可能感兴趣的:(python:批量压缩图片质量)