1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | use strict; |
3 | | | use warnings; |
4 | | | use diagnostics; |
5 | | | |
6 | | | use File::Find; |
7 | | | use lib "./lib"; |
8 | | | use HotSaNICparser; |
9 | | | |
10 | | | my $module=$ARGV[0] || ""; |
11 | | | $module=~ s/modules\///; |
12 | | | $module="/".$module; |
13 | | | if ($module eq "/") {$module="";} |
14 | | | |
15 | | | my %CONFIG = HotSaNICparser::get_config("."); |
16 | | | my $thumbsize = $CONFIG{THUMBSIZE} || "20%"; |
17 | | | my $method = $CONFIG{CONVERTMETHOD} || "HTML"; |
18 | | | |
19 | | | if ($module ne "") {print "converting ",$CONFIG{WEBDIR},$module,"\n";} |
20 | | | |
21 | | | # exit if method is HTML or unknown |
22 | | | if (index("ImgMgck I::M",$method) == -1) { exit 0; } |
23 | | | |
24 | | | # check if the ImageMagick perl-module is installed |
25 | | | if ($method eq 'I::M') { |
26 | | | eval { require Image::Magick; }; |
27 | | | if ($@) { |
28 | | | print "$0: Perlmodule Image::Magick not installed\n"; |
29 | | | $method = "ImgMgck"; |
30 | | | } else { |
31 | | | require Image::Magick; |
32 | | | print "Using Image::Magick perl-module\n"; |
33 | | | } |
34 | | | } |
35 | | | |
36 | | | # build array with all weekly diagram files in the web-dir |
37 | | | # |
38 | | | require File::Find; |
39 | | | my @files; |
40 | | | $File::Find::name=""; # suppress stupid warning... |
41 | | | File::Find::find( {wanted => sub { /^.*-week\..*\z/s && push @files, $File::Find::name; } }, $CONFIG{WEBDIR}.$module); |
42 | | | |
43 | | | my $cmd; |
44 | | | |
45 | | | foreach my $file ( @files ) { |
46 | | | my $thumb=$file; |
47 | | | $thumb=~ s/^(.+)\/(.+)-week\.(.+)$/$1\/thumb-$2\.$3/; |
48 | | | # print "$file -> $thumb\n"; |
49 | | | print "resizing $file\n"; |
50 | | | |
51 | | | if ($method eq "I::M") { |
52 | | | my $image = new Image::Magick; |
53 | | | $image->Read($file); |
54 | | | $image->Scale(geometry => "$thumbsize"); |
55 | | | $image->Write($thumb); |
56 | | | } |
57 | | | else { |
58 | | | if ( -x $CONFIG{CONVERTPATH} ) { |
59 | | | $cmd = "$CONFIG{CONVERTPATH} -geometry $thumbsize $file $thumb"; |
60 | | | # print "$cmd\n"; |
61 | | | system($cmd) == 0 |
62 | | | or warn "$0: could not convert $file to $thumb: $!"; |
63 | | | } |
64 | | | } |
65 | | | } |
66 | | | |
67 | | | exit; |
68 | | | |