jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [convert.pl] - Blame information for rev 2

 

Line No. Rev Author Line
11simandl#!/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
6use strict;
7use warnings;
8use diagnostics;
9use File::Find;
10 
11# include HotSaNIC libraries
12use lib "./lib";
13use 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 
18my $module=$ARGV[0] || "";
19$module=~ s/modules\///;
20$module="/".$module;
21if ($module eq "/") {$module="";}
22 
23my %CONFIG = HotSaNICparser::get_config(".");
24my $thumbsize = $CONFIG{THUMBSIZE} || "20%";
25my $method = lc $CONFIG{CONVERTMETHOD} || "html";
26my $binpath= $CONFIG{CONVERTPATH} || "";
27 
28if (-f $binpath) { $binpath =~ s/\/\w*$//g; }
29 
30my %METHODS=("imgmgck"=>"ImgMgck","imagemagick"=>"ImgMgck","i::m"=>"I::M","netpbm"=>"netpbm");
31 
32# exit if method is HTML or unknown
33if (! defined $METHODS{$method}) { exit 0; }
34else { $method=$METHODS{$method}; }
35 
36if ($module ne "") {print "converting ",$CONFIG{WEBDIR},$module,"\n";}
37 
38# check if the ImageMagick perl-module is installed
39if ($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#
52require File::Find;
53my @files;
54$File::Find::name=""; # suppress stupid warning...
55File::Find::find( \&wanted_files , $CONFIG{WEBDIR}.$module);
56sub wanted_files { /^.*-week\..*\z/s && push @files, $File::Find::name; }
57my $cmd;
58 
59foreach 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 
86exit;
87 

Powered by WebSVN 2.2.1