use strict; use warnings; use Image::ExifTool qw(:Public); use Date::Calc qw/Date_to_Time/; my $imageDir = './images'; my %timeFiles; ### Read each file's EXIF info and convert to seconds ### A Hash of Arrays (HoA) is used in case images have the same time for my $image (<$imageDir/*>) { # Skip image if no DateTimeOriginal info (highly unlikely) next unless my $dateTime = ImageInfo($image)->{DateTimeOriginal}; # Convert 'YYYY:MM:DD HH:MM:SS' to seconds my $time = Date_to_Time( split /[:\s]/, $dateTime ); push @{ $timeFiles{$time} }, $image; } ### ### Sort the times from the hash my @times = sort { $a<=>$b } keys %timeFiles; ### Group together the pix whose time is less than MAX_TIME_DIFF seconds ### apart my $MAX_TIME_DIFF=10; # Minimum time between photos my $MIN_GRP_SIZE=3; # Minimum "interesting" group size my @groups; my $cur_group = [ shift @times ]; while (@times) { if ($$cur_group[-1]+$MAX_TIME_DIFF >= $times[0]) { # small interval, add to current group push @$cur_group, shift @times; } else { # store last group (if interesting) and start # a new one. push @groups, $cur_group if @$cur_group >= $MIN_GRP_SIZE; $cur_group = [ shift @times ]; } } ### ### Get each group for my $group(@groups){ # The time in each group for my $time(@$group){ # The hash value is an array ref # $_ takes the value of each array element, viz., a file name print "$_: $time\n" for @{ $timeFiles{$time} }; } # Print blank lines between groups print "\n\n"; }