Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl =head1 NAME gimp-ahsv - Apply "Autostetch HSV" effect on a number of JPEG images =head1 SYNOPSIS gimp-ahsv [options] FILE... Options: -?, --help --man -v, --verbose =head1 OPTIONS =over 4 =item B<-?> =item B<--help> Print a brief help message and exits. =item B<--man> Prints the manual page and exits. =item B<-v> =item B<--verbose> This option increases the amount of information you given during program run. By default, gimp-ahsv works silently. =head1 DESCRIPTION This program applies "Image/Colors/Auto/Autostetch HSV" effect from gimp in batch mode on a number of JPEG images. This effect often improves contrast of pictures and improves their overall look. =head1 BUGS AND LIMITATIONS Loading and saving JPEG files decreases quality of the images. For the purposes I use this script such quality drop is acceptable. If it is not acceptiable for you than use other formats. You should replace file_jpeg_load/file_jpeg_save method calls with other methods from file_xxx_load/file_xxx_save family if you want to use this script with other formats. Unfortunately even in batch mode gimp requires X server so it is impos +sible to run this script without it. =head1 COPYRIGHT Copyright (c) 2002 Ilya Martynov. All rights reserved. This program is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License. =head1 SEE ALSO L<Gimp> PDB explorer in gimp =cut use strict; use warnings; use Pod::Usage; # configure Getopt::Long to parse argument string in GNU style use Getopt::Long qw(:config gnu_getopt); my @files; my $verbose; BEGIN { # Gimp module insists on parsing @ARGV on its own; for this reason # argument string is parsed here my %options; GetOptions(\%options, 'help|?', 'verbose|v+', 'man'); pod2usage(-exitval => 0, -verbose => 2, -output => \*STDOUT) if $options{man}; pod2usage(-exitval => 0, -output => \*STDOUT) if $options{help}; @files = @ARGV; pod2usage(2) unless @files; $verbose = $options{verbose} || 0; } use Gimp; use Gimp::Fu; # init Gimp modules Gimp::set_trace(TRACE_ALL) if $verbose > 1; Gimp::init; for my $file (@files) { print "Loading $file ...\n" if $verbose > 0; my $img = eval { Gimp->file_jpeg_load($file, $file) }; if($@) { # catch file loading errors and skip to the next file warn $@; next; } print "Applying effect ...\n" if $verbose > 0; my $drawable = $img->active_drawable; $img->plug_in_autostretch_hsv($drawable); print "Saving $file ...\n" if $verbose > 0; my $quality = 0.8; my $smoothing = 0; my $optimize = 1; my $progressive = 1; my $comment = ''; my $subsmp = 0; my $baseline = 1; my $restart = 0; my $dst = 2; eval { Gimp->file_jpeg_save($img, $drawable, $file, $file, $quality, $smoothing, $optimize, $progressive, $comment, $subsmp, $baseline, $restart, $dst); }; if($@) { # catch file saving errors and skip to the next file warn $@; next; } # free memory $img->delete; }
Update: I forgot to put Gimp->file_jpeg_save into eval. Fixed.

Ilya Martynov (

In reply to Batch conversion of images using gimp and Perl by IlyaM

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [1nickt]: Discipulus Yes, I think it is maybe easier to be a good monk in "real" life when you are young and idealistic or old and weary ... nost so much in middle age.
    [1nickt]: 😲 ... or did you mean the Middle Ages, when monastic life was more, umm, "earthy" ?!

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (7)
    As of 2017-12-13 14:05 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (368 votes). Check out past polls.