commit ec0fa9fd20ade097de645eac16df450a027a9251
parent a2653a9d8a70ee89088a617213a251bbff5d4ce5
Author: lumidify <nobody@lumidify.org>
Date: Mon, 27 Jul 2026 15:27:23 +0200
Treat metadata values consisting only of whitespace as nonexistent
Diffstat:
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/imagedatadupes b/imagedatadupes
@@ -51,6 +51,14 @@ sub load_exif_data {
for my $ignore (@exif_ignore) {
delete $info->{$ignore};
}
+ # Remove all undefined/empty values since there are sometimes images
+ # that are identical, except that one contains just whitespace for
+ # a metadata value
+ for my $key (keys %$info) {
+ if (!defined $info->{$key} || $info->{$key} =~ /^\s*$/) {
+ delete $info->{$key};
+ }
+ }
return $info;
}
@@ -80,7 +88,7 @@ sub compare_exif_data {
# (e.g. ThumbnailImage is a reference)
if (exists $info2_keys->{$key} && Compare($info1->{$key}, $info2->{$key}) == 1) {
# NOP
- } elsif (!exists $info2_keys->{$key} || !defined $info2->{$key} || $info2->{$key} eq "") {
+ } elsif (!exists $info2_keys->{$key}) {
if ($key eq "Warning") {
warn "WARNING: ExifTool gave a warning on $filename1 but not on $filename2\n";
warn "Treating these files as different to be on the safe side.\n";
@@ -90,7 +98,7 @@ sub compare_exif_data {
$info1_superset = 1;
warn "$filename1 includes $key which is empty/nonexistent in $filename2\n" if ($verbose);
} else {
- warn "$key is different for $filename1 and $filename2\n" if ($verbose);
+ warn "$key is \"$info1->{$key}\" for $filename1 but \"$info2->{$key}\" for $filename2\n" if ($verbose);
return -1;
}
delete $info1_keys->{$key};
@@ -272,7 +280,7 @@ sub handle_group_image_data {
my @extra_exif_ignore;
my $no_default_exif_ignore = 0;
my $show_help = 0;
-my $isolate = 0; # only find duplicates between different commandline arguments (i.e. not within one directory that is given)
+my $isolate = 0;
my $print_ignored = 0;
my $skip_exact_equality = 0;
my $delete_files = 0;
@@ -519,7 +527,8 @@ The images are first compared using signatures of the image data calculated with
Then, images with matching signatures are compared for exact equality of the image data. Lastly,
the metadata returned by ExifTool(1) is compared (this includes various metadata tags, not just
EXIF data). If the metadata in one file is a superset of the metadata in another file, the
-former is preferred over the latter when deciding which files to keep.
+former is preferred over the latter when deciding which files to keep. Note that a metadata value
+which is empty or only contains whitespace is treated as if it does not exist.
The specific use-case for this is files where the EXIF data was modified to add a comment (e.g. where
a photo was taken). If an old copy of the same image still exists, it won't be found as a duplicate