How Perl helped me with my mythmas presents, part 1
For the annual winter gift-giving season [0], I usually prepare a printout of nice pictures I took during the past year for the grandparents of my kids and other relatives. This involves going through 2839 photos [1] and filtering out the 10 to 30 pictures a given relative might care most about (there is some overlap, eg. the birthday of one of my kids, but not that much).
So the task is:
- go through a lot of photos quickly
- select/tag some with different criteria
- export the selected photos.
I once wrote a thing called fotagger, but currently my SDL is broken and I wasn't in the mood to fix it. So I took a closer look at the tool I'm usually using to view pictures: qiv.
qiv "is a very small and pretty fast gdk/Imlib image viewer" [2]. I knew
you can select and delete pictures using a
and d
, which copies the
current picture into .qiv-select and .qiv-trash
, respectively. But
that's not enough for my needs, because I want some pictures to go to my
mother, and different ones for my father, etc.
Further reading of the man-page revealed a workable solution based on true
Unix mindset: If you hit any number (or ^some_string
), qiv will run a
program called qiv-command
, passing the number you pressed (or
'some_string') and the filename of the picture you're currently watching
to said program.
But: qiv comes without qiv-command. It is up to you, the user, to implement this program, using whatever language you like and implementing whatever features you need. Fucking Brilliant!
So I now have this in my $PATH
:
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use Path::Class;
use File::Copy;
my ($action, $in_file_name) = @ARGV;
my $out = Path::Class::dir('/home/domm/media/fotos/select',$action);
die "no such dir $out" unless -d $out;
my $in = Path::Class::dir->file($in_file_name);
$in_file_name =~ s{/+}{_}g;
copy($in->stringify,$out->file($in_file_name)->stringify);
I just have to remember which relative gets what number, and now just have to press the according number to have the image I'm currently watching copied to a convenient location with a convenient filename [3].
So, a big THANKS to whoever though of providing this very easy to extend API. And of course another THANKS to all people working on Perl etc, which makes it absurdly easy for me to cobble something like the above together.
0: Even though I'm an atheist I usually say 'Christmas', but I sort of like mythmas, a funny term a search for alternative names for the annual winter gift-giving season suggested.
1: tree -F ~/media/fotos/2010/2010* | grep \* | wc -l
2: qiv website.
3: My pictures live in something like
2010/20100501_island/img_NNNNN.jpg
. After pressing eg 3
this image
would be found in select/3/20100501_island_img_NNNNN.jpg
qiv is nice - I've been searching for something like it for some time. Thank you!
By the way: grep has a count option (-c), so you don't need "| wc -l" in your unorthodox image finder oneliner.
oh, yes, I keep forgetting about `grep -c` ever since I learned about `wc -l`