]> www.wagner.pp.ru Git - oss/imgwww.git/blobdiff - imagedir
Moved from imagemagick to netpbm for scaling
[oss/imgwww.git] / imagedir
index b11888229b171e704c410474879065e0b4170d37..dbcde4bccb593d1e0ae7820594d8f547f6919f81 100755 (executable)
--- a/imagedir
+++ b/imagedir
@@ -1,4 +1,8 @@
 #!/usr/bin/perl
+use utf8;
+use Encode;
+use locale;
+use open OUT => ":locale";
 use constant THUMBSIZE => 150;
 use constant COLUMNS=>5;
 use constant THUMBDIR=>".thumbs";
@@ -54,18 +58,22 @@ Title. If none given, directory name is used.
 =cut
 
 use vars qw($opt_t $opt_n $opt_l $opt_f);
+our %decoders=('image/gif'=>'giftopnm','image/tiff'=>'tifftopnm','image/jpeg'=>'djpeg');
+
 getopts("t:lnf");
 
 my $dir = $opt_t || (split ("/",cwd()))[-1];
 mkdir THUMBDIR if (! -d THUMBDIR);
 mkdir INLINEDIR if (! -d INLINEDIR);
 my $i=0;
-open OUT,">index.html";
+open OUT,">","index.html";
 print OUT "<HTML><HEAD><TITLE>$dir</TITLE>\n<BODY>\n<H1>$dir</H1>\n"
 ."<p align=\"center\"><A HREF=\"..\">back</A></p>". 
  "<TABLE CELLSPACING=10 CELLPADDING=0 BORDER=0>\n";
-my @piclist=(<*.jpg>,<*.gif>,<*.png>) ;
-print STDERR "@piclist\n";
+my @piclist=grep (/\.(jpe?g|png|tiff?|gif)$/i, <*>) ;
+my @movielist= grep(/\.(mp4|avi|flv|mpg)$/i,<*>); 
+print STDERR "Pictures found @piclist\n";
+print STDERR "Videos found @movielist\n";
 my ($prev,$next);
 for ($j=0;$j<=$#piclist;$j++) {
   $_ = $piclist[$j];
@@ -76,6 +84,7 @@ for ($j=0;$j<=$#piclist;$j++) {
    $next = undef;
   } 
   print STDERR "$j:$_";
+  chmod 0644, $_;
   my $info = image_info($_);
   my $thumbname=rescale($_,THUMBDIR,THUMBSIZE,$info);
   my $inlinename=rescale($_,INLINEDIR,INLINESIZE,$info);
@@ -96,6 +105,7 @@ print OUT "</table></body></html>\n";
 close OUT;
 
 sub rescale {
+  no locale;
   my ($name,$out_dir,$maxsize,$info) = @_;
   my ($w,$h) = dim($info);
   if ($w<$maxsize && $h<$maxsize) {
@@ -103,10 +113,21 @@ sub rescale {
        return $name;
   }    
   my $result = "$out_dir/$name";
+  $result .= ".jpg" unless $result=~/\.jpe?g$/i;
   if ( ! -f $result || -M $name < -M $result) {
     print STDERR "  $out_dir...";
-
-    system "convert", "-geometry", $maxsize."x".$maxsize,$_,$result;
+       my $scale;
+       if ($w > $h) {
+               $scale = $maxsize*1.0/$w;
+       } else {
+               $scale = $maxsize*1.0/$h;
+       }
+       my $ftype= $info->{file_media_type};
+       die "Unknown image type for $name: $ftype\n"
+               if (not exists $decoders{$ftype});
+       my $decoder=$decoders{$ftype};
+    system "$decoder \"$name\" | pnmscale -xscale ". $scale . " -yscale " .
+               "$scale |cjpeg > $result";
     print STDERR "\b\b\b ";
   } 
   return $result;
@@ -114,9 +135,7 @@ sub rescale {
 
 sub make_comment_html {
   my $info = shift;
-my $comment =
-
-       ref($info->{"Comment"})?join("\n",@{$info->{"Comment"}}):$info->{"Comment"};
+my $comment = Encode::decode("koi8-r",ref($info->{"Comment"})?join("\n",@{$info->{"Comment"}}):$info->{"Comment"});
        $comment =~s/\&/&amp;/;
        $comment =~s/"/&quot;/;
        $comment =~s/>/&gt;/;
@@ -129,7 +148,7 @@ sub make_html {
        my $info = shift;
        my $comment = shift;
        my $inline = shift;
-       open HTML, ">$imgfile.html";
+       open HTML, ">", "$imgfile.html";
        my ($w,$h) = dim($info);
        my ($w1,$h1) = dim(image_info(INLINEDIR."/".$imgfile));
        print HTML "<html><head><title>$dir:$imgfile</title></head><body>