#!/usr/bin/perl # (C) 2000-2003 Midgard Systems Group # Name this index.cgi, put it in your top level photos directory, # make sure it's executable and that your 'DirectoryIndex' line contains # 'index.cgi'. Change $basepath appropriately. use Image::Size; $basepath = '/Geek/photos/'; ($thispath = $ENV{REQUEST_URI}) =~ s|^$basepath||; @dirs=(); @files=(); opendir(D,"."); while($_=readdir(D)) { next if /^\./; push @dirs, $_ if -d $_; push @files, $_ if -e $_; push @links, $_ if -l $_ && ! -e $_; $linkdest{$_} = readlink($_) if -l $_ && ! -e $_; } closedir(D); @dirs = sort @dirs; @files = sort @files; if($thispath) { $parent = $thispath; $parent =~ s|/?[^/]+/?$||; unshift @dirs, $parent = $basepath.$parent; } foreach (@files) { push @images,$_ if /\.(?:jpg|gif|png)$/i; push @videos,$_ if /\.(?:avi|mov|rm|asf)$/i; } print << 'EOF'; Content-type: text/html Photos
EOF if(@dirs) { foreach (@dirs) { print qq[ $_$_] unless $_ eq $parent; print qq[ Parent directoryParent Directory] if $_ eq $parent; print qq[    \n]; } print qq[
\n]; print qq[
\n]; } foreach (@images) { my($imx, $imy) = imgsize($_); ($metafile = $_) =~ s!(jpg|gif|png)$!!i; $metafile .= 'txt'; $alttag = $_; if(-f $metafile) { open(F,"<$metafile"); $metadata = join('',); close(F); $metadata =~ s/\n-----\n/ \/ /gs; $metadata =~ s/[\+\_\)\(\*\&\^\%\$\#\@\!\~\=\-\`\[\]\{\}\;\:\"\,\.\<\>\?\|\\]/ /gs; $metadata =~ s|\s+| |gs; $metadata =~ s|^\s+||s; $metadata =~ s|\s+$||s; if(length($metadata)<100) { $alttag = $metadata; } else { $metadata = substr($metadata,0,100); $metadata =~ s/\s*\S+$//; $alttag = $metadata . "..."; } } my($thumbnail, $imwidth, $imheight) = get_thumbnail("./".$_); my $thumburl = $thumbnail; $thumburl =~ s|\./||; $thumburl = &tourl($thumburl); $s = ""; $s .= ""; $s .= "\n"; print $s; } if(@videos) { print qq[
\n]; print qq[
\n]; foreach (@videos) { print qq[ $_$_]; if(my @s=stat) { if($s[7] > 1024*1024) { print " (", int($s[7]/1024/1024), "M)"; } elsif($s[7] > 1024) { print " (", int($s[7]/1024), "K)"; } else { print qq[ ($s[7]b)]; } } print qq[    \n]; } } if(@links) { print qq[
\n]; print qq[
\n]; foreach (@links) { print qq[ $_$_]; print qq[    \n]; } } print << 'EOF';
EOF sub tourl { my($path) = @_; $path =~ s!([ \@\%\&\=\\\?])!sprintf("%%%2.2x", ord($1))!eg; return $path; } sub get_thumbnail { my($file) = @_; $file =~ m|^(.*)/([^/]+)\.([^/\.]+)$|si; my($path, $filename, $ext) = ($1,$2,$3); $thumbpath = $path . '/.thumbnails/' . $filename . '.gif'; if(-f $thumbpath) { my($thumbwidth, $thumbheight) = imgsize($thumbpath); return ($thumbpath, $thumbwidth, $thumbheight); } $thumbdir = $path . '/.thumbnails/'; mkdir $thumbdir unless -d $thumbdir; my($imwidth, $imheight) = imgsize($file); @st=stat($file); return undef if $st[7] > 1000000; $cmd = "/usr/local/bin/convert -antialias -geometry '160x160>' $file $thumbpath"; system $cmd; my($thumbwidth, $thumbheight) = imgsize($thumbpath); return ($thumbpath, $thumbwidth, $thumbheight); return ($file, $imwidth, $imheight); }