-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate_thumbs.pl
More file actions
executable file
·169 lines (133 loc) · 3.46 KB
/
create_thumbs.pl
File metadata and controls
executable file
·169 lines (133 loc) · 3.46 KB
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
#!/usr/bin/perl -w
# Perl script by 'Turbo Fredriksson' <turbo@tripnet.se>
# Use at your own risk...
# Make sure we flush the buffers...
use FileHandle;
STDOUT->autoflush(1);
$DEBUG = 0;
# Do we have any arguments?
if( $ARGV[0] ) {
# Ohh yes.... Process it...
foreach $arg (@ARGV) {
if( $arg eq '--help' || $arg eq '-h' || $arg eq '?' ) {
&help();
} elsif( $arg eq '--index' || $arg eq '-i' ) {
exit 1 if(! $ARGV[1] );
$DIR = $ARGV[1];
&index($DIR);
exit 0;
} elsif( $arg eq '--debug' || $arg eq '-d' ) {
$DEBUG = 1;
} elsif( $arg =~ /^\// ) {
$DIR = $ARGV[0];
&main($DIR);
exit 0;
} else {
&help()
}
}
} else {
&help();
}
sub main {
local($DIR) = @_;
# Make sure the 'mini' directory exists...
printf("Minidir: '$DIR.mini'\n") if( $DEBUG );
if(! -e "\"$DIR.mini\"" ) {
# Nope, create it...
mkdir("$DIR.mini", 0755);
}
open(LIST, "find '$DIR' -maxdepth 1 -type f \| sort |");
while(! eof(LIST) ) {
$path = <LIST>;
chomp($path);
($dir, $file) = &basename($path);
printf "Creating thumbnail '$DIR.mini/$file': ";
&convert("$dir/$file", "$DIR.mini/$file");
printf "done.\n";
}
}
sub convert {
local($source, $dest) = @_;
# Convert the file...
system("convert -auto-orient -thumbnail 200x200 '$source' '$dest'");
}
sub index {
local($DIR) = @_;
my($LINE, @TMP, %DIRS, $i, $top_dir, $dir);
# Check to see if the directory exists...
if( -e $DIR ) {
print "Finding in dir: $DIR\n";
# Open the directory...
open(LIST, "/usr/bin/find '$DIR' -mindepth 1 -type d |")
|| die "Could not find, $!\n";
while(! eof(LIST) ) {
$LINE = <LIST>;
chomp($LINE);
next if( $LINE =~ /xvpics/ );
push(@TMP, $LINE);
}
close(LIST);
}
# Prepare a sort of the list...
for($i = 0; $TMP[$i]; $i++ ) {
$DIRS{$TMP[$i]} = $TMP[$i];
}
undef @TMP;
undef $i;
$top_dir = $DIR;
# ------------------------------------------------------
# Create the left side frame...
printf("Creating LEFT frame... ");
open(LEFT, "> $DIR/left.html" )
|| die "Could not open $DIR/left.html, $!\n";
foreach $dir (sort(keys %DIRS)) {
$dir =~ s/\.mini//g;
$dir =~ s/$top_dir\///g;
print LEFT <<EOF;
<LI><A HREF="/cgi-bin/list-pics_2.pl?$top_dir?$dir"
onMouseOver="window.status='$dir' ;return true"
onMouseOut="window.status='';return true"
TARGET=main>$dir</A></LI>
EOF
;
}
printf("done.\n");
}
sub basename {
my($line) = @_;
my(@path, @result, $dir, $i, $file);
# print "LINE: $line\n";
@path = split('/', $line);
for($i = 0; $path[$i+1]; $i++) {
# print "path[$i]: '$path[$i]'\n";
$dir .= $path[$i];
if( $path[$i+2] ) {
$dir .= "/";
}
}
# print "path[$i]: '$path[$i]'\n";
$file = $path[$i];
# We have path and a file name...
# print "$dir : $file\n";
push @result, $dir;
push @result, $file;
return(@result);
}
sub header {
print <<EOF;
Content-type: text/html
<HTML>
<HEAD>
<TITLE>Pics in $DIR</TITLE>
<META NAME="Author" CONTENT="CGI-BIN by Turbo Fredriksson">
</HEAD>
EOF
;
}
sub help {
print "\nUsage: $0 <picdir>\n";
print " or: $0 --index To create the frames page.\n\n";
print " directory is the exact path to where the pictures reside.\n";
exit 0;
}