#!/usr/bin/perl -w # # Example 5-4. Adjust Alpha # A plug-in for the GIMP, written in Perl. # use strict; use Gimp qw(:auto N_); Gimp::on_query(\&query); Gimp::on_run(\&run); sub query { gimp_install_procedure( "perl_fu_adjust_alpha", # Name "Adjust the curves of a channel.", # Blurb "Similar to ->Colors->Curves, for alpha channel.", # Help "Shawn Wallace", # Author "(c) 2003 IFC", # Copyright "2003-3-12", # Date N_ "/ORA Examples/Adjust Alpha", # Menu path "RGBA, GRAYA", # Images accepted Gimp::PROC_PLUG_IN, [ [PARAM_INT32, "run_mode", "Interactive, [non-interactive]"], [PARAM_IMAGE, "image", "The image"], [PARAM_DRAWABLE, "drawable", "The drawable"], ], [] ); } sub run { # First get the parameters passed to the procedure... my ($run_mode, $img, $drawable) = @_; if ($run_mode == Gimp::RUN_INTERACTIVE) { my $vector = adjust_alpha_dialog(); if ($vector) { gimp_undo_push_group_start($img); Gimp->progress_init("Adjusting alpha..."); $drawable->curves_explicit(4, 256, $vector); $drawable->update(0, 0, $drawable->width, $drawable->height); gimp_undo_push_group_end($img); Gimp->displays_flush(); } return STATUS_SUCCESS; } else { return STATUS_CALLING_ERROR; } } sub adjust_alpha_dialog { my $return_val; Gimp::gtk_init(); my $window = new Gtk::Dialog; $window->set_title("Adjust Curves"); $window->signal_connect(destroy => sub { $return_val = 0; Gtk->main_quit }); my $curve = new Gtk::Curve(); $curve->set_range(0, 255, 0, 255); # x-min, x-max, y-min, y-max $curve->set_curve_type('spline'); $window->vbox->add($curve); my $button = new Gtk::Button("OK"); $button->can_default(1); $button->grab_default; $button->signal_connect(clicked => sub { $return_val = 1; Gtk->main_quit }); $window->action_area->add($button); $window->show_all; main Gtk; if ($return_val) { return ([$curve->get_vector(256)]); } else { return undef; } } exit main;