![]() ![]() |
hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/env perl# $Id: convert.pl,v 1.20 2004/05/17 18:24:14 bernisys Exp $# include PERL librariesuse strict;use warnings;use diagnostics;use File::Find;# include HotSaNIC librariesuse lib "./lib";use HotSaNICparser;(my $VERSION = '$Revision: 1.20 $') =~ s/.*(\d+\.\d+).*/$1/;(my $IDENTIFIER = '$Id: convert.pl,v 1.20 2004/05/17 18:24:14 bernisys Exp $') =~ s/.*,v (.*) \$/$1/;my $module=$ARGV[0] || "";$module=~ s/modules\///;$module="/".$module;if ($module eq "/") {$module="";}my %CONFIG = HotSaNICparser::get_config(".");my $thumbsize = $CONFIG{THUMBSIZE} || "20%";my $method = lc $CONFIG{CONVERTMETHOD} || "html";my $binpath= $CONFIG{CONVERTPATH} || "";if (-f $binpath) { $binpath =~ s/\/\w*$//g; }my %METHODS=("imgmgck"=>"ImgMgck","imagemagick"=>"ImgMgck","i::m"=>"I::M","netpbm"=>"netpbm");# exit if method is HTML or unknownif (! defined $METHODS{$method}) { exit 0; }else { $method=$METHODS{$method}; }if ($module ne "") {print "converting ",$CONFIG{WEBDIR},$module,"\n";}# check if the ImageMagick perl-module is installedif ($method eq 'I::M') {eval { require Image::Magick; };if ($@) {print "$0: Perlmodule Image::Magick not installed\n";$method = "ImgMgck";} else {require Image::Magick;print "Using Image::Magick perl-module\n";}}# build array with all weekly diagram files in the web-dir#require File::Find;my @files;$File::Find::name=""; # suppress stupid warning...File::Find::find( \&wanted_files , $CONFIG{WEBDIR}.$module);sub wanted_files { /^.*-week\..*\z/s && push @files, $File::Find::name; }my $cmd;foreach my $file ( @files ) {my $thumb=$file;$thumb=~ s/^(.+)\/(.+)-week\.(.+)$/$1\/thumb-$2\.$3/;print "resizing $file\n";if ($method eq "I::M") {my $image = new Image::Magick;$image->Read($file);$image->Scale(geometry => "$thumbsize");$image->Write($thumb);}elsif ($method eq "ImgMgck") {$thumbsize=~ s/\./,/g;$cmd = "$binpath/convert -geometry $thumbsize $file $thumb";system($cmd) == 0 or warn "$0: could not convert $file to $thumb: $!";}elsif ($method eq "netpbm") {if ($thumbsize =~ /%/) {$thumbsize=~ s/%//g;$thumbsize=~ s/,/./g;$thumbsize/=100;}if ($file =~ /\.gif$/) { $cmd="$binpath/giftopnm $file | $binpath/pnmscale $thumbsize | $binpath/pnmtopng > $thumb"; }elsif ($file =~ /\.png/) { $cmd="$binpath/pngtopnm $file | $binpath/pnmscale $thumbsize | $binpath/pnmtopng > $thumb"; }system($cmd) == 0 or warn "$0: could not convert $file to $thumb: $!";}}exit;