From fecdcaf90e2c963d774ffbeca1b244f024be0a20 Mon Sep 17 00:00:00 2001 From: Q Date: Sun, 14 Apr 2024 11:55:53 +0300 Subject: [PATCH 1/4] better thr --- files/image_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/image_list.py b/files/image_list.py index 197c108..243d4a1 100755 --- a/files/image_list.py +++ b/files/image_list.py @@ -669,7 +669,7 @@ def find_fingerprint_nearest(opts): ''' Find nearest match to given file ''' cmp=os.path.realpath(opts.similarity.rsplit(",")[0]) - thr=sys.maxint + thr=65535 if len(opts.similarity.rsplit(","))>1: thr=int(opts.similarity.rsplit(",",1)[1]) conn=sqlite3.connect(opts.sqlfile) From e965b8803cad7db0a59a974fd9f66677b4998aef Mon Sep 17 00:00:00 2001 From: Q Date: Sun, 14 Apr 2024 11:58:55 +0300 Subject: [PATCH 2/4] add first, delete later --- py-packages/imagelist2/imagelist2/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py-packages/imagelist2/imagelist2/__init__.py b/py-packages/imagelist2/imagelist2/__init__.py index fc35874..3a2d18b 100644 --- a/py-packages/imagelist2/imagelist2/__init__.py +++ b/py-packages/imagelist2/imagelist2/__init__.py @@ -746,11 +746,11 @@ def main(): il = ImageList(options) if options.command == "db": - if not options.no_delete: - il.delete_missing() if not options.no_add: il.recursive_add() il.base_add() + if not options.no_delete: + il.delete_missing() if not options.no_delete_data: il.clean_data() if options.measure: From c53c57ede2cbfb5c2a0253543e4057862f516fad Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Sun, 21 Apr 2024 10:13:58 +0300 Subject: [PATCH 3/4] show image count --- py-packages/imagelist2/imagelist2/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/py-packages/imagelist2/imagelist2/__init__.py b/py-packages/imagelist2/imagelist2/__init__.py index 3a2d18b..750a4cc 100644 --- a/py-packages/imagelist2/imagelist2/__init__.py +++ b/py-packages/imagelist2/imagelist2/__init__.py @@ -9,7 +9,7 @@ from imagelist2.db import DB, sqlite_sqrt, sqlite_square from imagelist2.image import ImageMeasure, is_image_extension from tqdm import tqdm -__version__ = "0.0.1" +__version__ = "0.0.2" SQLFILE = "image-list.sqlite" # IMGMATCH = re.compile("|".join([".*\." + x + "$" |.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I) BADDIRS = ["_tn", "_med", ".tn", ".med"] @@ -26,6 +26,7 @@ class ImageList: def recursive_add(self): dir_count = 0 + image_count = 0 for path, dirs, files in os.walk(os.path.realpath(self.options.startpath), followlinks=self.options.symlinks): clean_dirs(dirs) dir_count += 1 @@ -60,21 +61,25 @@ class ImageList: if self.db.is_hash_mismatch(image): has_changed = True if has_changed: + image_count += 1 self.add_single(image, change=True) else: if not self.options.no_add: + image_count += 1 self.add_single(image, change=False) self.db.conn.commit() + if image_count > 0: + print(f"Added/changed {image_count} images") return def add_single(self, image, change=False): if change: query = "UPDATE list SET hash=?, date=? ,size=? WHERE file=?" - error_msg = f"error adding file: {image.filename}" + error_msg = f"error adding image: {image.filename}" else: query = "INSERT INTO list(hash,date,size,file) VALUES (?,?,?,?)" - error_msg = f"error changing file: {image.filename}" + error_msg = f"error changing image: {image.filename}" try: self.db.cursor().execute( @@ -145,7 +150,7 @@ class ImageList: cursor.execute("DELETE FROM list where file == ?", (file,)) self.db.conn.commit() if len(to_delete) > 0: - print(f"Cleaned {len(to_delete)} files") + print(f"Cleaned {len(to_delete)} images") return def clean_data(self): From f91bce10d4dbb8d6c713326c55dbaff5ab5a0c98 Mon Sep 17 00:00:00 2001 From: Q Date: Fri, 3 May 2024 21:05:05 +0300 Subject: [PATCH 4/4] description from jpeg --- py-packages/imagelist2/imagelist2/__init__.py | 7 ++++--- py-packages/imagelist2/imagelist2/image.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/py-packages/imagelist2/imagelist2/__init__.py b/py-packages/imagelist2/imagelist2/__init__.py index 750a4cc..3b51d35 100644 --- a/py-packages/imagelist2/imagelist2/__init__.py +++ b/py-packages/imagelist2/imagelist2/__init__.py @@ -9,7 +9,7 @@ from imagelist2.db import DB, sqlite_sqrt, sqlite_square from imagelist2.image import ImageMeasure, is_image_extension from tqdm import tqdm -__version__ = "0.0.2" +__version__ = "0.0.3" SQLFILE = "image-list.sqlite" # IMGMATCH = re.compile("|".join([".*\." + x + "$" |.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I) BADDIRS = ["_tn", "_med", ".tn", ".med"] @@ -124,13 +124,14 @@ class ImageList: continue image = ImageMeasure(filename) cursor.execute( - """INSERT INTO data(hash,portrait,width,height) - VALUES(?,?,?,?)""", + """INSERT INTO data(hash,portrait,width,height,description) + VALUES(?,?,?,?,?)""", ( row[0], image.get_portrait(), image.get_width(), image.get_height(), + image.get_description() ), ) if i % 50 == 0: diff --git a/py-packages/imagelist2/imagelist2/image.py b/py-packages/imagelist2/imagelist2/image.py index 36c5fc7..deb2cab 100644 --- a/py-packages/imagelist2/imagelist2/image.py +++ b/py-packages/imagelist2/imagelist2/image.py @@ -111,6 +111,12 @@ class ImageMeasure: self.portrait = self.height >= self.width return self.width, self.height, self.portrait + def get_description(self): + if self.description is None: + self.description = read_image_comment(self.filename) + return self.description + + def get_image(self, image_type="numpy"): if self.image is None: @@ -227,3 +233,8 @@ def read_image_size(fname): """Just reading the size is faster with PIL""" im = Image.open(fname) return im.width, im.height + +def read_image_comment(fname): + """Just reading the comment with PIL""" + im = Image.open(fname) + return im.info.get('comment','')