summaryrefslogtreecommitdiff
path: root/bin/dthumb
blob: 32931f921f7c24b95ffb12b23fa38f79926178f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/perl
# Copyright © 2009-2016 by Daniel Friesel <derf@chaosdorf.de>
# License: WTFPL:
#     You just DO WHAT THE FUCK YOU WANT TO
use strict;
use warnings;
use 5.010;
use autodie;

use App::Dthumb;
use Getopt::Long qw(:config no_ignore_case);
use IO::Handle;
use Time::Progress;

STDERR->autoflush(1);

my $opt = {};
my $id  = 1;

our $VERSION = '0.2';

#<<<
GetOptions(
	$opt,
	qw{
		all|a
		help|h
		no-names|n
		quality|q=i
		quiet|Q
		recreate|r
		recursive|R
		size|d=i
		spacing|s=f
		title|t=s
		version|v
	},
) or die("Please see perldoc -F $0\n");
#>>>
my $dthumb = App::Dthumb->new( %{$opt} );
my $timer  = Time::Progress->new();

if ( $opt->{version} ) {
	say "dthumb version $VERSION";
	exit 0;
}
if ( $opt->{help} ) {
	exec( 'perldoc', '-F', $0 );
	die("Please see 'perldoc -F $0' or 'man dthumb'\n");
}

$dthumb->read_directories;
$dthumb->create_files;
$dthumb->delete_old_thumbnails;

$timer->attr(
	min => 1,
	max => scalar $dthumb->get_files,
);

for my $file ( $dthumb->get_files ) {
	if ( not $opt->{quiet} ) {
		print STDERR $timer->report(
			"\r\e[KCreating Thumbnails: %p done, %L elapsed, %E remaining",
			$id++, );
	}

	$dthumb->create_thumbnail_html($file);
	$dthumb->create_thumbnail_image($file);
}
if ( not $opt->{quiet} ) {
	print "\n";
}

$dthumb->write_out_html;

__END__

=head1 NAME

dthumb - Generate file index with thumbnails for a directory.

=head1 SYNOPSIS

B<dthumb> [B<-anrR>] [B<-d> I<size>] [B<-s> I<spacing>] [B<-t> I<title>]
[B<-q> I<quality>]

=head1 VERSION

version 0.2

=head1 DESCRIPTION

B<dthumb> creates an HTML index with thumbnails for all images found in the
current directory.  It uses a javascript lightbox (see
L<http://fancyapps.com/fancybox/>) to display images.  To view them without the
lightbox, open images by clicking on the filename instead of the thumbnail.

Note that recursion is not yet supported.

During operation, B<dthumb> will show its progress on STDERR.

=head1 OPTIONS

=over

=item B<-a>, B<--all>

Also include non-image files in the file listing

=item B<-n>, B<--no-names>

Do not show image names below thumbnails

=item B<-r>, B<--recreate>

Recreate all thumbnails

=item B<-R>, B<--recursive>

Also include directories in the file listing

=item B<-d>, B<--size> I<maxsize> (default: 200)

Set maximum thumbnail size. Thumbnails are created so that neither width nor
height exceed I<maxsize> pixels.

=item B<-s>, B<--spacing> I<float> (default: 1.1)

Use I<float> as spacing factor.
The size of each image element (image + border around it) is the
number of pixels (see --size) times I<float>.
So for B<1.1> you have a small border around each image, for B<1.0> you have
no border at all, etc.

=item B<-t>, B<--title> I<string>

Set HTML document title. Defaults to the basename of the current directory

=item B<-q>, B<--quality> I<int> (default: 75)

Set thumbnail quality.
Accepts values between 0 and 100, where 100 is the highest possible quality.

=back

=head1 EXIT STATUS

Zero upon success, non-zero otherwise.

=head1 CONFIGURATION

None.

=head1 FILES

B<dthumb> always works in the current working directory.  It will create the
file F<index.html>, in which the HTML code for the thumbnail list is saved.

It also creates two directories: F<.thumbs> for the thumbnail images, and
F<.dthumb> for CSS and lightbox code.

=head1 DEPENDENCIES

=over

=item * autodie (Included in core as of perl 5.10.1)

=item * Data::Section

=item * Image::Imlib2

=item * Time::Progress

=back

=head1 BUGS AND LIMITATIONS

Report issues either by mail to E<lt>derf@chaosdorf.deE<gt> or on
E<lt>http://github.com/derf/dthumb/issuesE<gt>.

=head1 AUTHOR

Copyright (C) 2009-2016 by Daniel Friesel E<lt>derf@chaosdorf.deE<gt>.

The lightbox code is (C) by JE<0x0101>nis Skarnelis under the license
CC-BY-NC 3.0. See L<http://fancyapps.com/fancybox/>.

=head1 LICENSE

For this program:

    0. You just DO WHAT THE FUCK YOU WANT TO

For the lightbox code (part of the generated HTML):

    CC-BY-NC 3.0