hier mal meine interpretation des codes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
use strict;
use GD;
use Image::Size;
use IO::File;
use IO::Dir;
use constant MAX_WIDTH => 80;
use constant MAX_HEIGHT => 80;
use constant IMAGEPATH => "/usr/local/httpd/htdocs/thumbs/";
resize_images(IMAGEPATH, ".jpg", MAX_WIDTH, MAX_HEIGHT);
sub resize_images
{
my ($folder, $ext, $maxwidth, $maxheight) = @_;
my $dir = new IO::Dir;
if($dir->open($folder))
{
while(defined(my $filename = $dir->read))
{
my $file = "$folder/$filename";
next if $file =~ /^\.\.?$/;
next if -d $file;
next if $file !~ /$ext$/io;
eval
{
my ($width, $height) = imgsize($file);
my $relation = ($height / $max_height) > ($width / $max_width) ? $height / $maxheight : $width / $maxwidth;
my $thumbnailheight = sprintf ("%.0f",$height / $relation);
my $thumbnailwidth = sprintf ("%.0f",$width / $relation);
my $big = GD::Image->newFromJpeg($file);
my $lit = new GD::Image($thumbnailwidth, $thumbnailheight);
$lit->copyResized($big, 0, 0, 0, 0, $thumbnailwidth, $thumbnailheight, $width, $height);
my $fh = new IO::File;
if($fh->open("> $file))
{
print $fh $lit->jpeg;
$fh->close();
}
undef $lit;
undef $big;
}
}
$dir->close();
}
}
\n\n
<!--EDIT|esskar|1090480259-->