Re: [問題] 如何檢查圖片是否和毀損已刪文

看板Python作者 (艾爾文)時間6年前 (2019/07/29 01:50), 編輯推噓1(100)
留言1則, 1人參與, 6年前最新討論串2/7 (看更多)
import os import shutil from time import sleep from PIL import Image,ImageTk import tkinter as tk from tkinter import StringVar def show_jpg(): root = tk.Tk() im=Image.open(imagefilename) img=ImageTk.PhotoImage(im) imLabel=tk.Label(root,image=img).pack() root.mainloop() class GetCode(object): def __init__(self): self.data={} # 存放回傳值 self.root = tk.Tk() self.root.geometry('140x130') self.root.resizable(width=False,height=False) # self.textLabel=tk.Label(self.root,text="'"+get_your_image_file+"'").pack() # self.textStr=StringVar() self.textEntry=tk.Entry(self.root,textvariable=self.textStr) self.textStr.set("") self.textEntry.pack() # 輸入框 im=Image.open(imagefilename) img=ImageTk.PhotoImage(im) imLabel=tk.Label(self.root,image=img).pack() # 顯示圖片 self.but = tk.Button(self.root,text="確認",command=self.return_code).pack(fill="x") # 按键 self.root.mainloop() def return_code(self): # 回傳輸入內容 self.data["code"]=self.textStr.get() self.root.destroy() # 關閉視窗 keyinfileName = YOUR_IMAGE_FOLDER + self.data["code"] + '.jpg' shutil.move(imagefilename, keyinfileName) # 更改圖片檔名 print(imagefilename , '->', keyinfileName, ' is done') print("輸入內容:",self.data["code"]) YOUR_IMAGE_FOLDER = "imput_images\\" OUTPUT_FOLDER = "output _images\\" get_your_image_files = os.listdir(YOUR_IMAGE_FOLDER) counts = {} for (i, get_your_image_file) in enumerate(get_your_image_files): while len(get_your_image_file) != 10: # 更改成你要的條件 imagefilename = YOUR_IMAGE_FOLDER + get_your_image_file # show_jpg() print("[INFO] processing image {}/{}: {}".format(i + 1, len(get_your_image_files), get_your_image_file)) GetCode() break ※ 引述《s4028600 (佑)》之銘言: : 我在網上爬到這個 : https://www.dust8.com/2017/04/22/python-broken-image/ : 我將他給的代碼存成py檔 : 放在圖片堆中執行 : 就閃一下消失了 : 想要讀取所有資料夾下的圖片 : 或是讀取同資料夾的所有圖片 : 我要如何改造這個代碼 : 求教學 ----- Sent from JPTT on my iPhone -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.186.172 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1564336237.A.122.html

07/29 02:01, 6年前 , 1F
感謝您的回應 只是我沒學過 根本看不懂...
07/29 02:01, 1F
文章代碼(AID): #1TFU1j4Y (Python)
討論串 (同標題文章)
文章代碼(AID): #1TFU1j4Y (Python)