Album
view release on metacpan or search on metacpan
script/album view on Meta::CPAN
@std_fields = qw(type seq next prev
dest_name orig_name assoc_name
timestamp file_size medium_size
tag description annotation
rotation mirror);
@exif_fields = qw(DateTime ExifImageLength ExifImageWidth
ExposureMode ExposureProgram ExposureTime
FNumber Flash FocalLength ISOSpeedRatings
ImageDescription Make Model
MeteringMode SceneCaptureType Orientation
height width file_ext);
$exif_rot = { top_left => [ 0, '' ], # 1: no corr. needed
top_right => [ 0, 'v' ], # 2: flop (V)
bot_right => [ 180, '' ], # 3: 180
bot_left => [ 0, 'h' ], # 4: flip (H)
left_top => [ 90, 'h' ], # 5: flip 90
right_top => [ 90, '' ], # 6: 90
right_bot => [ 90, 'v' ], # 7: flop 90
left_bot => [ 270, '' ], # 8: 270
};
}
my $largepat;
sub basename_nolarge {
my ($f) = @_;
unless ( $largepat ) {
$largepat = quotemeta(::d_large());
$largepat = qr;^$largepat[/\\];;
}
$f =~ s;$largepat;;;
$f;
}
sub new {
my ($pkg, $file) = @_;
$pkg = ref($pkg) if ref($pkg);
my $self = { $file ?
(orig_name => $file,
dest_name => basename_nolarge($file)) : (),
description => "",
annotation => [],
tag => "",
};
if ( $file && -f $file ) {
my @st = stat(_);
my $ii = ::cache_entry($file);
if ( $ii ){
$self = $ii;
delete($self->{$_}) foreach grep { /^_/ } keys(%$self);
}
# Else, get image info.
else {
my $ii = Image::Info::image_info($file);
$self->{file_size} = $st[7];
$self->{timestamp} = $st[9];
unless ( exists($ii->{error}) ) {
for my $key ( @exif_fields ) {
my $val = $ii->{$key};
next unless defined $val;
if ( $key eq "Orientation" ) {
($self->{rotation}, $self->{mirror}) =
@{$exif_rot->{$val}}
if exists $exif_rot->{$val};
}
else {
$val = $val->as_float
if UNIVERSAL::can($val,"as_float");
$self->{$key} = $val;
}
}
::cache_entry($file, $self);
}
}
# Actualize.
$self->{file_size} = $st[7];
$self->{timestamp} = $st[9];
}
bless($self, $pkg);
}
INIT {
no strict 'refs';
for my $sub ( @std_fields, @exif_fields ) {
$sub = "_".$sub if $sub eq "rotation";
*{"ImageInfo::$sub"} = sub {
my ($self, $value) = @_;
$self->{$sub} = $value if defined($value);
$self->{$sub};
};
}
}
sub rotation {
my ($self) = @_;
defined($self->{_rotation}) ? $self->{_rotation} : $self->{rotation};
}
sub html_name {
my ($self) = @_;
sprintf("img%04d.html", $self->seq);
}
package FileList;
use Class::Struct "FileList" =>
[ _tally => '$',
_data => '$',
_hash => '$',
];
sub add {
my ($self, $el, $name) = @_;
my $data = $self->_data;
my $hash = $self->_hash;
$self->_hash($hash = {}) unless $hash;
( run in 0.587 second using v1.01-cache-2.11-cpan-39bf76dae61 )