| 1 | 1 | simandl | #!/usr/bin/env perl |
| 2 | | | |
| 3 | | | # $Id: convert.pl,v 1.20 2004/05/17 18:24:14 bernisys Exp $ |
| 4 | | | |
| 5 | | | # include PERL libraries |
| 6 | | | use strict; |
| 7 | | | use warnings; |
| 8 | | | use diagnostics; |
| 9 | | | use File::Find; |
| 10 | | | |
| 11 | | | # include HotSaNIC libraries |
| 12 | | | use lib "./lib"; |
| 13 | | | use HotSaNICparser; |
| 14 | | | |
| 15 | | | (my $VERSION = '$Revision: 1.20 $') =~ s/.*(\d+\.\d+).*/$1/; |
| 16 | | | (my $IDENTIFIER = '$Id: convert.pl,v 1.20 2004/05/17 18:24:14 bernisys Exp $') =~ s/.*,v (.*) \$/$1/; |
| 17 | | | |
| 18 | | | my $module=$ARGV[0] || ""; |
| 19 | | | $module=~ s/modules\///; |
| 20 | | | $module="/".$module; |
| 21 | | | if ($module eq "/") {$module="";} |
| 22 | | | |
| 23 | | | my %CONFIG = HotSaNICparser::get_config("."); |
| 24 | | | my $thumbsize = $CONFIG{THUMBSIZE} || "20%"; |
| 25 | | | my $method = lc $CONFIG{CONVERTMETHOD} || "html"; |
| 26 | | | my $binpath= $CONFIG{CONVERTPATH} || ""; |
| 27 | | | |
| 28 | | | if (-f $binpath) { $binpath =~ s/\/\w*$//g; } |
| 29 | | | |
| 30 | | | my %METHODS=("imgmgck"=>"ImgMgck","imagemagick"=>"ImgMgck","i::m"=>"I::M","netpbm"=>"netpbm"); |
| 31 | | | |
| 32 | | | # exit if method is HTML or unknown |
| 33 | | | if (! defined $METHODS{$method}) { exit 0; } |
| 34 | | | else { $method=$METHODS{$method}; } |
| 35 | | | |
| 36 | | | if ($module ne "") {print "converting ",$CONFIG{WEBDIR},$module,"\n";} |
| 37 | | | |
| 38 | | | # check if the ImageMagick perl-module is installed |
| 39 | | | if ($method eq 'I::M') { |
| 40 | | | eval { require Image::Magick; }; |
| 41 | | | if ($@) { |
| 42 | | | print "$0: Perlmodule Image::Magick not installed\n"; |
| 43 | | | $method = "ImgMgck"; |
| 44 | | | } else { |
| 45 | | | require Image::Magick; |
| 46 | | | print "Using Image::Magick perl-module\n"; |
| 47 | | | } |
| 48 | | | } |
| 49 | | | |
| 50 | | | # build array with all weekly diagram files in the web-dir |
| 51 | | | # |
| 52 | | | require File::Find; |
| 53 | | | my @files; |
| 54 | | | $File::Find::name=""; # suppress stupid warning... |
| 55 | | | File::Find::find( \&wanted_files , $CONFIG{WEBDIR}.$module); |
| 56 | | | sub wanted_files { /^.*-week\..*\z/s && push @files, $File::Find::name; } |
| 57 | | | my $cmd; |
| 58 | | | |
| 59 | | | foreach my $file ( @files ) { |
| 60 | | | my $thumb=$file; |
| 61 | | | $thumb=~ s/^(.+)\/(.+)-week\.(.+)$/$1\/thumb-$2\.$3/; |
| 62 | | | print "resizing $file\n"; |
| 63 | | | if ($method eq "I::M") { |
| 64 | | | my $image = new Image::Magick; |
| 65 | | | $image->Read($file); |
| 66 | | | $image->Scale(geometry => "$thumbsize"); |
| 67 | | | $image->Write($thumb); |
| 68 | | | } |
| 69 | | | elsif ($method eq "ImgMgck") { |
| 70 | | | $thumbsize=~ s/\./,/g; |
| 71 | | | $cmd = "$binpath/convert -geometry $thumbsize $file $thumb"; |
| 72 | | | system($cmd) == 0 or warn "$0: could not convert $file to $thumb: $!"; |
| 73 | | | } |
| 74 | | | elsif ($method eq "netpbm") { |
| 75 | | | if ($thumbsize =~ /%/) { |
| 76 | | | $thumbsize=~ s/%//g; |
| 77 | | | $thumbsize=~ s/,/./g; |
| 78 | | | $thumbsize/=100; |
| 79 | | | } |
| 80 | | | if ($file =~ /\.gif$/) { $cmd="$binpath/giftopnm $file | $binpath/pnmscale $thumbsize | $binpath/pnmtopng > $thumb"; } |
| 81 | | | elsif ($file =~ /\.png/) { $cmd="$binpath/pngtopnm $file | $binpath/pnmscale $thumbsize | $binpath/pnmtopng > $thumb"; } |
| 82 | | | system($cmd) == 0 or warn "$0: could not convert $file to $thumb: $!"; |
| 83 | | | } |
| 84 | | | } |
| 85 | | | |
| 86 | | | exit; |
| 87 | | | |