]>
iEval git - app-gallery.git/blob - lib/App/Gallery.pm
7 use File
::Basename qw
/fileparse/;
9 use File
::Path qw
/make_path/;
11 use File
::Spec
::Functions qw
/catdir catfile/;
12 use HTML
::Template
::Compiled
;
15 our $VERSION = '0.001001';
18 my %default_args = (tmpl
=> '', title
=> 'Gallery', width
=> 600, height
=> 600);
21 my (undef, $args, @images) = @_;
22 my %args = (%default_args, %$args);
23 my $full = catfile
$args{out
}, 'full';
24 my $thumb = catfile
$args{out
}, 'thumb';
25 my $tmpl = HTML
::Template
::Compiled
->new(
26 (($args{tmpl
} // '') eq '')
27 ?
(scalarref
=> \
$default_template)
28 : (filename
=> $args{tmpl
}),
29 default_escape
=> 'HTML',
31 make_path
$full, $thumb;
33 for my $path (@images) {
34 my $basename = fileparse
$path;
35 my $thumb_path = catfile
$thumb, $basename;
36 my $dest_path = catfile
$full, $basename;
38 link $path, $dest_path or cp
$path, $dest_path or die "$!";
40 my $img = Image
::Magick
->new;
42 my ($width, $height) = $img->Get('width', 'height');
43 my $aspect_ratio = $width / $height;
44 if ($width > $args{width
}) {
45 $width = $args{width
};
46 $height = $width / $aspect_ratio;
48 if ($height > $args{height
}) {
49 $height = $args{height
};
50 $width = $height * $aspect_ratio;
52 $img->Thumbnail(width
=> $width, height
=> $height);
53 $img->Write($thumb_path);
57 title
=> $args{title
},
58 images
=> [map { scalar fileparse
$_ } @images]
61 my $index = catfile
$args{out
}, 'index.html';
62 write_file
$index, $tmpl->output;
65 $default_template = <<'EOF';
67 <title><tmpl_var title></title>
68 <meta charset="utf-8">
71 display: inline-block;
73 vertical-align: center;
77 <link rel="stylesheet" href="style.css">
79 <h1><tmpl_var title></h1>
81 <tmpl_loop images><div class=imgwrap><a href='full/<tmpl_var _>'><img src='thumb/<tmpl_var _>'></a></div>
92 App::Gallery - Very basic picture gallery
100 App::Gallery is a script for creating a very basic picture gallery out
101 of a list of pictures.
107 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
109 =head1 COPYRIGHT AND LICENSE
111 Copyright (C) 2017 by Marius Gavrilescu
113 This library is free software; you can redistribute it and/or modify
114 it under the same terms as Perl itself, either Perl version 5.24.2 or,
115 at your option, any later version of Perl 5 you may have available.
This page took 0.057914 seconds and 5 git commands to generate.