Python Forum

Full Version: Remove duplicate images - tkinter?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am able to generate strings that hold the location of duplicate images on my hard drive but I am trying to figure out how to see a thumbnail of the original and the duplicate image (side by side) before I choose delete. I am a bit stuck about the design of this. Is this maybe a tkinter type problem? I guess each in a pane of some kind and make a button that says delete or skip? Any ideas. I have the searching stuff all worked out and have the paths of putative dupes.
tkinter will work, this is not a trivial program, but not that difficult either.
You will want to create a basic window, something like: https://pythonprogramming.net/python-3-t...-tutorial/
will get you going, then place your images on top of buttons using PhotoImage.

you should be able to find many examples using google
That makes sense. If the buttons have the images on top then I can just press to keep or delete. Then the next pair can slide into place. Should go fast. Many thanks.

Just an update: I needed to use PIL to get my jpegs usable on widgets under tkinter. Then I took a pair of images (resized and merged them) and put the combined image on a button. So this idea is working in 2.7 and 3.5. I did need to resolve some name space collision. I think that PIL and tkinter were both trying to use "Image". Anyway, I may instead put my image on a label rather than a button and use plain buttons to decide whether to delete a duplicate. At this point I can hit a button to bring up the next image on a label (itself on a canvas) but there is a bit of 'lag' - maybe half a second I guess because of the resize.
you can use something like:

for all in someList:
    Image = Image.open("assets/default.gif")
	Image = Image.resize((32, 32), Image.ANTIALIAS)
    Icon = ImageTk.PhotoImage(Image)
    visable_object= Lable(someelemet, image=Icon)
    visable_object.pack(side=TOP)
you can replace (32, 32) with the x, y size you want to show the image in.
If the image doesnt show and you are sure the path is correct try cast Icon to a global variable or as self.Icon = ImageTk.PhotoImage(Image), i think this has something to do with storing the image in RAM and had some issues with it before.

Hope that helps
So far everything works as expected.

I end up just putting an image (made of a pair of images) onto a canvas and that works. I can inspect the image before deleting the duplicate. So all is well, almost.
I make use of this code:

import PIL.Image

class PhotoRec:
   'Common base class for all Photo Records - name file size location '
   recCount = 0

   def __init__(self, file_name, file_path, file_size):
      self.file_name = file_name
      self.file_path = file_path
      self.file_size = file_size
      self.twin_file = "notset" # for full path of a 'twin' if it exists
      self.thumb_img = PIL.Image.new('RGB', (128,128))
      self.make_thumb_image()
      self.delete_flag=False
      PhotoRec.recCount += 1
      
   
   def displayCount(self):
     print ("recCount = ", PhotoRec.recCount)

   def displayStuff(self):
      print ( "file_name is:",  self.file_name )
      print ( "file_path is:",  self.file_path )
      print ( "file_size is:",  self.file_size )
      print ( PhotoRec.recCount    )


   def  make_thumb_image (self):
    
      
      q2 =self.file_path + "/" + self.file_name
      temp = PIL.Image.open(q2)
      size = 128,128
      self.thumb_img = temp.resize(size   )
Now my next task is to store about 10000 small images for later use. I have read about using pickle so maybe that is what I want. I want to use those 10000 thumbnails week after week so I need to be able to save them onto my hard drive and retrieve them as needed. Would anyone know if this is a sensible way to proceed (using pickle)? Thanks.
One of the available packages may already do this for you, see: https://pypi.org/search/?q=image+thumbnails
if not, it's simple to save a file:

def save_image(image, filename):
    with open(filename, 'wb') as fp:
        fp.write(image)