Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created December 20, 2019 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lestrrat/1c6ad12b54c104894c79c072848d7a9d to your computer and use it in GitHub Desktop.
Save lestrrat/1c6ad12b54c104894c79c072848d7a9d to your computer and use it in GitHub Desktop.
卒園式のDVD作るのに特定の命名規則に沿った写真ファイルを送ってこいって指令があったので…
use strict;
use lib "local/lib/perl5";
use Data::Dumper;
use Image::ExifTool qw(:Public);
use Time::Piece;
my $name = "___CHILD'S_NAME___";
my @files;
for my $file (glob("*.jpg")) {
my $info = ImageInfo($file);
my $date = $info->{FileModifyDate};
$date =~ s/\+09:00/+0900/;
my $tp = Time::Piece->strptime($date, '%Y:%m:%d %H:%M:%S%z');
push @files, { dt => $tp, file => $file };
}
@files = sort { $a->{dt} <=> $b->{dt} } @files;
my $count = 1;
for my $file (@files) {
my $flattened = flatten_to_year($file->{dt});
my $filename = sprintf(
'%d_%s_%s%02d.jpg',
$flattened - 2014,
$file->{dt}->strftime('%y%m%d'),
$name,
$count,
);
$count++;
warn $filename;
system("cp $file->{file} data/$filename");
}
sub flatten_to_year {
my $tp = shift;
if ($tp->year == 2013) {
return 2014;
}
if ($tp->mon < 4) {
return $tp->year - 1;
}
return $tp->year;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment