Apache-Throttle
view release on metacpan or search on metacpan
throttleimg view on Meta::CPAN
rename "$file.dir", $file or die $!;
print "Creating control file for $time seconds.\n" unless $quiet;
open (CONF, "> $file/.throttle") or die $!;
flock (CONF, 2);
print CONF "$time\n";
close CONF;
my $des = "0";
for my $i (0 .. $steps - 1) {
my $percent = $i / $steps;
my $image = new Image::Magick;
$image->Read("$file/Z-$file");
my ($width, $height) = $image->Get("width", "height");
my @changes = ();
if (!$same_size) {
my $new_width = $width * (.25 + .75 * $percent);
my $new_height = $height * (.25 + .75 * $percent);
$image->Scale(width => $new_width, height => $new_height);
push(@changes, "size=${new_width}x${new_height}");
}
if (!$same_quality && ($image->Get("magick") eq "JPG")) {
my $quality = 10 + 90 * $percent;
$image->Set(quality => $quality);
push(@changes, "quality=${quality}%");
}
if (!$same_colors && ($image->Get("magick") eq "GIF")) {
my $colors = 10 + 245 * $percent;
$image->Quantize(colors => $colors, colorspace => "RGB",
dither => "true");
push(@changes, "colors=$colors");
}
$image->Write("$file/" . ++$des . "-$file");
print "Wrote $des-$file, ", (-s "$file/$des-$file"), " bytes: ",
join(", ", @changes), "\n" unless $quiet;
}
print "Original is now Z-$file, ", (-s "$file/Z-$file"),
( run in 0.316 second using v1.01-cache-2.11-cpan-10c994e2082 )