python 圖片處理 窗體

 

#coding:utf-8
##重慶話語科技---運維部--蓮花子
##python/shell
##羣號:35666534   歡迎你

import multiprocessing
import _thread,time,re,sys,fnmatch
import os,urllib,random,threading,shutil
from tkinter import *
from glob import glob
sys.path.append("/Users/lianhuazi/Desktop")
from shuiyin import *


def T1msg(envent):
	E7.insert(INSERT,"%s\n"%envent)

def init():
	E1.insert(INSERT,'*.jpg')
	E2.insert(INSERT,50)
	E3.insert(INSERT,50)
	E4.insert(INSERT,50)
	E5.insert(INSERT,50)
	E6.insert(INSERT,"我是進度條")
def clearentry(envent):
	E2.delete(0.0,END)

def clearentry5(envent):
	E5.delete(0,END)

def clearentry1(envent):
	global files
	files=None
	E1.delete(0,END)

def scandir():
	filesbox=[]
	for root, dirs, files in os.walk("/Users/lianhuazi/Desktop/img/"):
		for f in files:
			print(f)
			filesbox.append(os.path.join(root,f))
	return filesbox

def msg(event):
	E6.delete(0,END)
	E6.insert(INSERT,event)
	
def fenxi(Image_type=None,w=None,h=None,cut=None,check=None):
	if check == 1:
		cmd="int(j[0])+int(w) >img_wmax[1][0]"
		if not os.path.exists("one"):
			os.mkdir("one")
			os.mkdir("two")
		sort_size={}
		name=glob(Image_type)
		for i in name:
			x,y,z=xxyy(i)
			sort_size.update({x:[y,z]})
		img_wmax=max(sort_size.items(),key=lambda p:(p[1][0]))
		img_wmin=min(sort_size.items(),key=lambda p:(p[1][0]))
		img_hmax=max(sort_size.items(),key=lambda p:(p[1][1]))
		img_hmin=min(sort_size.items(),key=lambda p:(p[1][1]))
		for i,j in sort_size.items():
			if eval(cmd):
				#pass
				shutil.move(i,"one")
				#print("one w:%s %s h:%s %s "%(int(j[0])+int(w),img_wmax[1][0],int(j[1])+int(h),img_hmax[1][1]))
			else:
				#pass
				shutil.move(i,"two")
				#print("two w:%s %s h:%s %s "%(int(j[0])+int(w),img_wmax[1][0],int(j[1])+int(h),img_hmax[1][1]))
	elif check == 2 :
		cmd="int(j[1])+int(h) >img_hmax[1][1]"
		if not os.path.exists("one"):
			os.mkdir("one")
			os.mkdir("two")
		sort_size={}
		name=glob(Image_type)
		for i in name:
			x,y,z=xxyy(i)
			sort_size.update({x:[y,z]})
		img_wmax=max(sort_size.items(),key=lambda p:(p[1][0]))
		img_wmin=min(sort_size.items(),key=lambda p:(p[1][0]))
		img_hmax=max(sort_size.items(),key=lambda p:(p[1][1]))
		img_hmin=min(sort_size.items(),key=lambda p:(p[1][1]))
		for i,j in sort_size.items():
			if eval(cmd):
				#pass
				shutil.move(i,"one")
				#print("one w:%s %s h:%s %s "%(int(j[0])+int(w),img_wmax[1][0],int(j[1])+int(h),img_hmax[1][1]))
			else:
				#pass
				shutil.move(i,"two")
				#print("two w:%s %s h:%s %s "%(int(j[0])+int(w),img_wmax[1][0],int(j[1])+int(h),img_hmax[1][1]))
	elif check == 3:
		files=scandir()	
		for i in files:
			if fnmatch.fnmatch(i,Image_type):
				try:
					c=shuiyin(i,'',i)
					c.img_b_cut(pix=int(cut))
					msg(i.split("/")[-1])
				except:
					T1msg(i)
		msg("over")
	elif check == 4:
		files=scandir()		
		for i in files:
			if fnmatch.fnmatch(i,Image_type):
				try:
					c=shuiyin(i,'',i)
					c.img_t_cut(pix=int(cut))
					msg(i.split("/")[-1])
				except:
					T1msg(i)
		msg("over")
	elif check == 5:
		files=scandir()
		for i in files:
			if fnmatch.fnmatch(i,Image_type):
				try:
					c=shuiyin(i,'',i)
					c.draw_transparent_text()
					c.resize()
					msg(i.split("/")[-1])
				except:
					T1msg(i)
		msg("over")
	elif check == 6:
		files=scandir()
		for i in files:
			if not re.findall(r"\.(jpg|jpeg)$",i):
				os.remove(i)
				msg(i.split("/")[-1])
		msg("over")
	elif check == 7:
		files=scandir()
		for i in files:
			if fnmatch.fnmatch(i,Image_type):
				os.rename(i,"%s.jpg"%i)
				msg(i.split("/")[-1])
		msg("over")
def xxyy(name):
	from PIL import Image
	fp = open(name,'rb')
	im = Image.open(fp)
	fp.close()
	x,y = im.size
	return(name,x,y)

mytop = Tk()

top=Frame()

top.pack(expand=YES,anchor="w")
v = IntVar()
v.set(1)
L1 = Label(top, text="圖片擴展名:")
#L2 = Label(top, text="width:")
#L3 = Label(top, text="Hight:")
L2=Radiobutton(top, text="根據寬分類:", variable=v, value=1)
L3=Radiobutton(top, text="根據高分類:", variable=v, value=2)
L4=Radiobutton(top, text="切底部像素", variable=v, value=3)
L5=Radiobutton(top, text="切頂部像素", variable=v, value=4)
L6=Radiobutton(top, text="調圖片大小", variable=v, value=5)
L7=Radiobutton(top, text="刪除不要的", variable=v, value=6)
L8=Radiobutton(top, text="批量更名字", variable=v, value=7)

L1.grid(row=0, column=1)
L2.grid(row=1, column=1)
L3.grid(row=2, column=1)
L4.grid(row=3, column=1)
L5.grid(row=4, column=1)
L6.grid(row=5, column=1)
L7.grid(row=6, column=1)
L8.grid(row=7, column=1)

E1 = Entry(top, bd =3,width=10)
E1.grid(row=0, column=2)
E1.bind('<Double-Button>',clearentry1)

E2 = Entry(top, bd =3,width=10)
E2.grid(row=1, column=2)
E2.bind('<Double-Button>',clearentry1)

E3 = Entry(top, bd =3,width=10)
E3.grid(row=2, column=2)
E3.bind('<Double-Button>',clearentry1)

E4 = Entry(top, bd =3,width=10)
E4.grid(row=3, column=2)
E4.bind('<Double-Button>',clearentry1)

E5 = Entry(top, bd =3,width=10)
E5.grid(row=4, column=2)

E6 = Entry(top, bd =3,width=10)
E6.grid(row=5, column=2)

E7 = Text(top, bd =3,width=50,height=10)
E7.grid(row=7, column=2)

B = Button(top,text="go fuck",command=lambda:_thread.start_new_thread(fenxi,(E1.get(),E2.get(),E3.get(),E4.get(),v.get())))
B.grid(row=0, column=3)
init()
mytop.mainloop()
相關文章
相關標籤/搜索