From ee25e6d65a124811cd847b61de6bbadc51f06eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uro=C5=A1=20Golja?= Date: Tue, 25 Oct 2016 23:10:05 +0200 Subject: [PATCH] Mostly beauty fixes. --- symlink-images-by-aspect-ratio.pl | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/symlink-images-by-aspect-ratio.pl b/symlink-images-by-aspect-ratio.pl index 94db729..2461eba 100755 --- a/symlink-images-by-aspect-ratio.pl +++ b/symlink-images-by-aspect-ratio.pl @@ -29,7 +29,7 @@ if (! -d $conf->{dst_dir}) { # gather the list of files my @list = find_wanted( sub { -f && ( /\.jpg$/i || /\.jpeg$/i ) }, - $conf->{"src_dir"} + $conf->{src_dir} ); if (! @list) { print "No files found.\n"; @@ -43,14 +43,14 @@ my $ars = {}; my $files = {}; # a hashref that holds all the files, their exif data, and their calculcated aspect ratio foreach my $f (@list) { $count++; - print "Gathering info for image in file: $f\n"; + print "Gathering info for image in file: '$f'\n"; my $e = Image::EXIF->new($f); my $exif = $e->get_image_info(); my ($x, $y, $error_flag); # Check for the existence of x if (!defined $exif->{"Image Width"}) { - print "WARNING: Could not find attribute 'Image Width'."; + print "WARNING: Could not find attribute 'Image Width'.\n"; $error_flag = 1; } else { @@ -59,7 +59,7 @@ foreach my $f (@list) { # Check for the existence of y if (!defined $exif->{"Image Height"}) { - print "WARNING: Could not find attribute 'Image Height'."; + print "WARNING: Could not find attribute 'Image Height'.\n"; $error_flag = 1; } else { @@ -68,29 +68,29 @@ foreach my $f (@list) { # Calculate aspect ratio and append it into the hash if ($error_flag) { - print "Unable to calculate aspect ratio for this image. Skipping." + print "WARNING: Unable to calculate aspect ratio for this image. Skipping it." } else { my $ar; $ar = nearest(0.01, ($x > $y) ? $x / $y : $y / $x) unless $error_flag; $ars->{$ar}++; - $files->{$f}->{"ar"} = $ar; + $files->{$f}->{ar} = $ar; } # Append the exif data into hash - $files->{$f}->{"exif"} = $exif; + $files->{$f}->{exif} = $exif; # bump the number of errors $errors++ if $error_flag; } -print "All images and their EXIF data:"; +# Dump the EXIF data of all images +print "All images and their EXIF data:\n"; print Dumper $files; print "\n"; -print "Total images found: $count\n"; -print "Images with invalid EXIF data: $errors\n"; - +# Dump some statistics +print "Total images found: $count. Images with invalid EXIF data: $errors\n"; print "Aspect ratio information for all images (aspect ratio => number of occurences):\n"; print Dumper $ars; print "\n"; @@ -98,7 +98,7 @@ print "\n"; # Create destination directories print "Creating destination directories: "; foreach my $d (keys %$ars) { - my $dirname = $conf->{"dst_dir"} . "/" . $d; + my $dirname = $conf->{dst_dir} . "/" . $d; print "'$dirname' "; mkdir $dirname; } @@ -107,12 +107,12 @@ print "\n"; # Symlink print "Symlinking source files into destination directories.\n"; foreach my $f (keys %$files) { - next unless exists $files->{$f}->{"ar"}; + next unless exists $files->{$f}->{ar}; # construct the symlink name my $name = basename($f); - my $ar = $files->{$f}->{"ar"}; - my $dest = $conf->{"dst_dir"} . "/" . $ar . "/" . $name; + my $ar = $files->{$f}->{ar}; + my $dest = $conf->{dst_dir} . "/" . $ar . "/" . $name; # symlink print "$f -> $dest\n";