Hi, sometimes you have a whole bunch of rgb files which are just too dark or light, and you want to adjust them all in one step. Well, I used to launch gimp and adjust each one individually, but that is a pain if you have more than a few files. Well here is a way with Imager.

The idea is very simple. You increase(decrease) the rgb values to adjust brightness, and you adjust the contrast with +- intensity.

Experiment on 1 first to get the best setting, then run it in a whole dir full of images. If you keep the $r $g $b values identical, the brightness change will be uniform, otherwise you will be adjusting "tint" as well.

#!/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" ); }

In reply to batch rgb brightness and contrast adjustment by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.