| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
200569
|
use v5.40; |
|
|
2
|
|
|
|
|
9
|
|
|
2
|
2
|
|
|
2
|
|
15
|
use feature 'class'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
407
|
|
|
3
|
2
|
|
|
2
|
|
17
|
no warnings "experimental::class"; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
296
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
class Snig::Image { |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.001'; # VERSION |
|
8
|
|
|
|
|
|
|
# ABSTRACT: Snig Image Class |
|
9
|
|
|
|
|
|
|
# PODNAME: Snig::Image |
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
702
|
use Log::Any qw($log); |
|
|
2
|
|
|
|
|
11475
|
|
|
|
2
|
|
|
|
|
15
|
|
|
12
|
2
|
|
|
2
|
|
5850
|
use Imager; |
|
|
2
|
|
|
|
|
125404
|
|
|
|
2
|
|
|
|
|
14
|
|
|
13
|
2
|
|
|
2
|
|
5877
|
use Image::ExifTool qw(ImageInfo); |
|
|
2
|
|
|
|
|
193469
|
|
|
|
2
|
|
|
|
|
479
|
|
|
14
|
2
|
|
|
2
|
|
795
|
use File::Copy qw(copy); |
|
|
2
|
|
|
|
|
7513
|
|
|
|
2
|
|
|
|
|
173
|
|
|
15
|
2
|
|
|
2
|
|
554
|
use File::Share qw(dist_file); |
|
|
2
|
|
|
|
|
41460
|
|
|
|
2
|
|
|
|
|
3844
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
field $file :reader :param; |
|
18
|
|
|
|
|
|
|
field $exif :reader; |
|
19
|
|
|
|
|
|
|
field $mtime :reader; |
|
20
|
|
|
|
|
|
|
field $created :reader; |
|
21
|
|
|
|
|
|
|
field $model :reader; |
|
22
|
|
|
|
|
|
|
field $orientation :reader; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
field $next :reader; |
|
25
|
|
|
|
|
|
|
field $prev :reader; |
|
26
|
|
|
|
|
|
|
field $pos :reader; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
ADJUST { |
|
29
|
|
|
|
|
|
|
$file = path($file) if !ref($file); |
|
30
|
|
|
|
|
|
|
$exif = ImageInfo($file->stringify); |
|
31
|
|
|
|
|
|
|
$mtime = $file->stat->mtime; |
|
32
|
|
|
|
|
|
|
$created = $exif->{'CreateDate'}; |
|
33
|
|
|
|
|
|
|
$model = $exif->{'Model'}; |
|
34
|
|
|
|
|
|
|
$orientation = $exif->{'Orientation'}; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
method set_chain($this_pos, $prev_image, $next_image) { |
|
38
|
|
|
|
|
|
|
$pos = $this_pos; |
|
39
|
|
|
|
|
|
|
$prev = $prev_image; |
|
40
|
|
|
|
|
|
|
$next = $next_image; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
method resize ( $outdir, $thumbnail, $detail, $force = 0 ) { |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
copy($file, $outdir->child('orig_'.$file->basename)) unless -e $outdir->child('orig_'.$file->basename); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my ($img, $w, $h, $format); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
for my $scale ({format=>'thumbnail',size=>$thumbnail},{format=>'preview',size=>$detail}) { |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $scaled_file_name = $scale->{format}.'_'.$file->basename; |
|
52
|
|
|
|
|
|
|
my $outfile = $outdir->child($scaled_file_name); |
|
53
|
|
|
|
|
|
|
next if ($outfile->is_file && !$force); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
unless ($img) { |
|
56
|
|
|
|
|
|
|
$img = Imager->new(file=>$file->stringify) || die Imager->errstr(); |
|
57
|
|
|
|
|
|
|
if ($orientation && $orientation =~ /(\d+) CW/) { |
|
58
|
|
|
|
|
|
|
my $degrees = $1; |
|
59
|
|
|
|
|
|
|
my $rotated = $img->rotate(right=>$degrees); |
|
60
|
|
|
|
|
|
|
$log->debugf("Rotated %s %s degrees right", $file->basename, $degrees); |
|
61
|
|
|
|
|
|
|
$img = $rotated; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
$w = $img->getwidth; |
|
64
|
|
|
|
|
|
|
$h = $img->getheight; |
|
65
|
|
|
|
|
|
|
$format = $w / $h; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $scaled; |
|
69
|
|
|
|
|
|
|
if ($format >= 1) { |
|
70
|
|
|
|
|
|
|
$scaled = $img->scale(xpixels => $scale->{size}) || die "Cannot scale $file: ".$img->errstr; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
else { |
|
73
|
|
|
|
|
|
|
my $scale_h = int($scale->{size}) / 3 * 2; # TODO get proper factor, needs to inspect all image formats in set |
|
74
|
|
|
|
|
|
|
$scaled = $img->scale(ypixels => $scale_h) || die "Cannot scale $file: ".$img->errstr; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$scaled->write(file=>$outfile, jpgquality=>100); |
|
78
|
|
|
|
|
|
|
$log->debugf("Scaled %s to %s", $file->basename, $outfile); |
|
79
|
|
|
|
|
|
|
local $|=1; |
|
80
|
|
|
|
|
|
|
print '.'; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
method url($format) { |
|
86
|
|
|
|
|
|
|
return $format .'_'. $file->basename; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
method html_file { |
|
90
|
|
|
|
|
|
|
my $html = lc($file->basename); |
|
91
|
|
|
|
|
|
|
$html =~s/\.(.*?)$/.html/; |
|
92
|
|
|
|
|
|
|
return $html; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
method write_html_page($tt, $output, $collection) { |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
$tt->process(dist_file('Snig','page.tt'), { |
|
98
|
|
|
|
|
|
|
image => $self, |
|
99
|
|
|
|
|
|
|
collection=> { |
|
100
|
|
|
|
|
|
|
name => $collection->name, |
|
101
|
|
|
|
|
|
|
size => scalar $collection->sorted, |
|
102
|
|
|
|
|
|
|
}, |
|
103
|
|
|
|
|
|
|
version => Snig->VERSION, |
|
104
|
|
|
|
|
|
|
}, $output->child($self->html_file)->stringify) || die $tt->error; |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |