Gimp

 view release on metacpan or  search on metacpan

lib/Gimp/Fu.pm  view on Meta::CPAN

      $layer->file_png_save($path,$path,$interlace,$compress,(!$noextra) x 5);
   } elsif ($type eq "PNM") {
      $layer->file_pnm_save($path,$path,1);
   } else {
      $layer->file_save($path,$path);
   }
}

sub main {
   return Gimp::main unless $Gimp::help;
   require Getopt::Long;
   my $proc;
   Getopt::Long::Configure('pass_through');
   Getopt::Long::GetOptions('p=s' => \$proc);
   my $this = find_script($proc);
   print __<<EOF;
       interface-arguments are
           -o | --output <filespec>   write image to disk
           -i | --interact            let the user edit the values first
EOF
   print "           -p <procedure> (one of @{[
      map { $_->[0] =~ s/^(?:perl_fu|plug_in)_//r; } @scripts
   ]})\n" if @scripts > 1;
   print "       script-arguments are\n" if @{($this // [])->[9] // []};
   for(@{($this // [])->[9] // []}) {
      my $type=$pf2info{$_->[0]}->[0];
      my $key=mangle_key($_->[1]);
      my $default_text = defined $_->[3]
	  ? " [".(ref $_->[3] eq 'ARRAY' ? "[@{$_->[3]}]" : $_->[3])."]"
	  : "";
      printf "           --%-24s %s%s\n",
	"$key $type",
	$_->[2],
	$default_text;
   }
   0;
}

1;
__END__

=head1 NAME

Gimp::Fu - Easy framework for Gimp-Perl scripts

=head1 SYNOPSIS

  use Gimp;
  use Gimp::Fu;
  podregister {
    # your code
  };
  exit main;
  __END__
  =head1 NAME

  function_name - Short description of the function

  =head1 SYNOPSIS

  <Image>/Filters/Menu/Location...

  =head1 DESCRIPTION

  Longer description of the function...

=head1 DESCRIPTION

This module provides all the infrastructure you need to write Gimp-Perl
plugins. Dov Grobgeld has written an excellent tutorial for Gimp-Perl.
You can find it at C<http://www.gimp.org/tutorials/Basic_Perl/>.

This distribution comes with many example scripts. One is
C<examples/example-fu.pl>, which is a small Gimp::Fu-script you can take
as a starting point for your experiments. You should be able to run it
from GIMP already by looking at "Filters/Languages/_Perl/Test/Dialog".

Your main interface for using C<Gimp::Fu> is the C<podregister> function.

=head1 PODREGISTER

This:

  podregister {
    # your code
  };

does the same as this:

  register '', '', '', '', '', '', '', '', '', sub {
    # your code
  };

It extracts all the relevant values from your script's POD documentation
- see the section on L</"EMBEDDED POD DOCUMENTATION"> for an
explanation. You will also notice you don't need to provide the C<sub>
keyword, thanks to Perl's prototyping.

=head2 AUTOMATIC PERL PARAMETER INSERTION

Thanks to L<Filter::Simple> source filtering, this C<podregister>-ed
function:

  # the POD "PARAMETERS" section defines vars called "x" and "y"
  # the POD "SYNOPSIS" i.e. menupath starts with "<Image>"
  # the POD "IMAGE TYPES" says "*" - this means image and drawable params too
  podregister {
     # code...
  };

will also have the exact equivalent (because it's literally this) of:

  podregister {
     my ($image, $drawable, $x, $y) = @_;
     # code...
  };

This means if you add or remove parameters in the POD, or change their
order, your code will just continue to work - no more maintaining two
copies of the parameter list. The above is the most common scenario,
but see the L</menupath> for the other possibilities for the variable



( run in 1.170 second using v1.01-cache-2.11-cpan-39bf76dae61 )