Python Forum
Remove duplicate images - tkinter?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove duplicate images - tkinter?
#1
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.
Reply
#2
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
Reply
#3
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.
Reply
#4
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
Reply
#5
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.
Reply
#6
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 983 Jan-16-2024, 06:44 PM
Last Post: rob101
  Problems trying to position images with Tkinter emont 3 760 Dec-12-2023, 07:20 AM
Last Post: menator01
  Tkinter - How can I remove the background borders from ttk.Button? TurboC 4 17,030 Oct-18-2020, 10:58 AM
Last Post: TurboC
  [Tkinter] Loading Images to Tkinter with Pillow Tomli 2 12,998 Jun-18-2020, 03:26 AM
Last Post: Tomli
  Images in tkinter menator01 0 1,599 Apr-25-2020, 12:49 AM
Last Post: menator01
  tkInter and Pillow don't display any images in GUIs - program gives errors instead SomeRandomGuy 9 10,780 Oct-29-2019, 02:57 PM
Last Post: SomeRandomGuy
  [Tkinter] how to remove black area around the graph in tkinter ? NEL 1 2,285 Aug-03-2019, 01:48 PM
Last Post: NEL
  [Tkinter] Help with tkinter; images and button commands SheeppOSU 2 2,991 Mar-28-2019, 02:01 AM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020