| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# mamgal - a program for creating static image galleries |
|
2
|
|
|
|
|
|
|
# Copyright 2007-2010 Marcin Owsiany |
|
3
|
|
|
|
|
|
|
# See the README file for license information |
|
4
|
|
|
|
|
|
|
# The picture encapsulating class |
|
5
|
|
|
|
|
|
|
package App::MaMGal::Entry::Picture; |
|
6
|
2
|
|
|
2
|
|
10
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
41
|
|
|
7
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
41
|
|
|
8
|
2
|
|
|
2
|
|
8
|
use base 'App::MaMGal::Entry'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
125
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
96
|
|
|
10
|
2
|
|
|
2
|
|
11
|
use App::MaMGal::Exceptions; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
1352
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub make |
|
13
|
|
|
|
|
|
|
{ |
|
14
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
15
|
0
|
|
|
|
|
|
my %opts = @_; |
|
16
|
0
|
|
0
|
|
|
|
my $force_slide = $opts{force_slide} || 0; |
|
17
|
0
|
|
|
|
|
|
return ($self->refresh_scaled_pictures, $self->refresh_slide($force_slide)); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub refresh_slide |
|
21
|
|
|
|
|
|
|
{ |
|
22
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
23
|
0
|
|
|
|
|
|
my $force = shift; |
|
24
|
0
|
0
|
|
|
|
|
my $tools = $self->tools or croak "Tools were not injected"; |
|
25
|
0
|
0
|
|
|
|
|
my $formatter = $tools->{formatter} or croak "Formatter required"; |
|
26
|
0
|
0
|
0
|
|
|
|
ref $formatter and $formatter->isa('App::MaMGal::Formatter') or croak "Arg is not a formatter"; |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$self->container->ensure_subdir_exists($self->slides_dir); |
|
29
|
0
|
|
|
|
|
|
my $name = $self->{dir_name}.'/'.$self->page_path; |
|
30
|
0
|
0
|
0
|
0
|
|
|
$self->container->_write_contents_to(sub { $formatter->format_slide($self) }, $self->page_path) unless ($self->fresher_than_me($name) and not $force); |
|
|
0
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $self->page_path; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub refresh_miniatures |
|
35
|
|
|
|
|
|
|
{ |
|
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
37
|
0
|
0
|
|
|
|
|
my @miniatures = @_ or croak "Need args: miniature specifications"; |
|
38
|
0
|
|
|
|
|
|
my $i = undef; |
|
39
|
0
|
|
|
|
|
|
my $r; |
|
40
|
|
|
|
|
|
|
my @ret; |
|
41
|
0
|
|
|
|
|
|
foreach my $miniature (@miniatures) { |
|
42
|
0
|
|
|
|
|
|
my ($subdir, $x, $y, $suffix) = @$miniature; |
|
43
|
0
|
0
|
|
|
|
|
my $relative_name = $subdir.'/'.$self->{base_name}.($suffix ? $suffix : ''); |
|
44
|
0
|
|
|
|
|
|
push @ret, $relative_name; |
|
45
|
0
|
|
|
|
|
|
my $name = $self->{dir_name}.'/'.$relative_name; |
|
46
|
0
|
0
|
|
|
|
|
next if $self->fresher_than_me($name); |
|
47
|
|
|
|
|
|
|
# loading image data deferred until it's necessary |
|
48
|
0
|
0
|
|
|
|
|
$i = $self->read_image unless defined $i; |
|
49
|
0
|
0
|
|
|
|
|
$r = $self->scale_into($i, $x, $y) and App::MaMGal::SystemException->throw(message => '%s: scaling failed: %s', objects => [$name, $r]); |
|
50
|
0
|
|
|
|
|
|
$self->container->ensure_subdir_exists($subdir); |
|
51
|
0
|
0
|
|
|
|
|
$r = $i->Write($name) and App::MaMGal::SystemException->throw(message => '%s: writing failed: %s', objects => [$name, $r]); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
0
|
|
|
|
|
|
return @ret; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
|
|
0
|
0
|
|
sub is_interesting { 1; } |
|
57
|
0
|
|
|
0
|
0
|
|
sub page_path { $_[0]->slides_dir.'/'.$_[0]->{base_name}.'.html' } |
|
58
|
0
|
|
|
0
|
0
|
|
sub thumbnail_path { $_[0]->thumbnails_dir.'/'.$_[0]->{base_name} } |
|
59
|
0
|
|
|
0
|
0
|
|
sub tile_path { $_[0]->{dir_name}.'/'.$_[0]->thumbnail_path } |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# This method does not operate on App::MaMGal::Entry::Picture, but this was the most |
|
62
|
|
|
|
|
|
|
# appropriate place to put it into. At least until we grow a "utils" class. |
|
63
|
|
|
|
|
|
|
sub scale_into |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
0
|
|
|
0
|
0
|
|
my $that = shift; |
|
66
|
0
|
|
|
|
|
|
my $img = shift; |
|
67
|
0
|
0
|
0
|
|
|
|
ref($img) and $img->isa('Image::Magick') or croak "Need arg: an image"; |
|
68
|
0
|
|
|
|
|
|
my ($x, $y) = @_; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
my $r; |
|
71
|
0
|
|
|
|
|
|
my ($x_pic, $y_pic) = $img->Get('width', 'height'); |
|
72
|
0
|
|
|
|
|
|
my ($x_ratio, $y_ratio) = ($x_pic / $x, $y_pic / $y); |
|
73
|
0
|
0
|
0
|
|
|
|
if ($x_ratio <= 1 and $y_ratio <= 1) { |
|
|
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return; # no need to scale |
|
75
|
|
|
|
|
|
|
} elsif ($x_ratio > $y_ratio) { |
|
76
|
0
|
|
|
|
|
|
return $img->Scale(width => $x, height => $y_pic / $x_ratio); |
|
77
|
|
|
|
|
|
|
} else { |
|
78
|
0
|
|
|
|
|
|
return $img->Scale(height => $y, width => $x_pic / $y_ratio); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |