#!/usr/bin/perl use warnings; use strict; use Imager; use File::Basename; # Usage: "scriptname red blue green contrast" # example: " script 2.0 2.0 0.5 2.0" # 1.0 is "no change", values less than 1 reduce my ($r,$g,$b,$c) = @ARGV; $r = $r || 1; $g = $g || 1; $b = $b || 1; $c = $c || 1; umask 0022; my @pics= <*.jpg *.gif *.png>; my @exts = qw(.jpg .gif .png); my $img = Imager->new(); my @redmap = map { int( $r * $_) } 0..255; my @greenmap = map { int( $g * $_) } 0..255; my @bluemap = map { int( $b * $_) } 0..255; foreach my $file (@pics){ my ($basename,$path,$suffix) = fileparse($file,@exts); $img->open(file=>$file) or die $img->errstr(); my $newimg = $img->copy(); $newimg->map( red=>\@redmap, green=>\@greenmap, blue=>\@bluemap ); $newimg->filter(type=>'contrast', intensity=> $c); $newimg->write(file=>"$basename-b$suffix" ); }