#!/usr/bin/perl -w # # Apply Tint # A plug-in for the GIMP, written in Perl. # use strict; use Gimp qw(:auto); use Gimp::Fu; Gimp::set_trace(TRACE_ALL); # Set to full trace mode register( "perl_fu_apply_tint", # Name "Apply a tint to an image.", # Blurb "=pod(HELP)", # Help "=pod(AUTHOR)", # Author "=pod(COPYRIGHT)", # Copyright "=pod(DATE)", # Date "/ORA Examples/Apply Tint", # Menu path "RGB*, GRAY*", # Images accepted # The parameters [ [ PF_COLOR, "tint_color", "The color to apply", [255, 0, 0]], [ PF_TOGGLE, "work_on_copy", "Work on a copy?", 0], ], # return values [], \&apply_tint # A reference to the plug-in code ); exit main; sub apply_tint { # The plug-in subroutine. # First get the parameters passed to the procedure... my ($img, $drawable, $tint_color, $work_on_copy) = @_; # If we create a copy, we want to return the new image, # otherwise we want to return undef my $return_val = undef; # Start an undo group; everything between the start and end of the # group can be undone in a single step. gimp_undo_push_group_start($img); # procedural-style syntax # Create a new copy of the image if "work on copy" is true. if ($work_on_copy) { $img = channel_ops_duplicate($img); $return_val = $img; # Set the drawable to the new active layer. $drawable = $img->get_active_layer; } # If the image is a grayscale, convert to RGB color mode unless ($drawable->is_rgb()) { $img->convert_rgb(); # gimp_convert_rgb() } # Since the plug-in operates on a selection area, we will select # the whole image if nothing is selected. unless ($drawable->mask_bounds) { $img->selection_all; } # Copy the selection into the paste buffer. gimp_edit_copy($drawable); # Paste the selection, and clear the current selection. # The drawable is now a floating selection layer. my $floating_layer = gimp_edit_paste($drawable, 0); # Apply a gaussian blur effect. plug_in_gauss_iir($img, $floating_layer, 5, 1, 1); # Because plug_in_colorify colors the white parts of a drawable # (and we want to color the black parts), we should invert it first. $floating_layer->invert(); # Colorify the floating layer plug_in_colorify($img, $floating_layer, $tint_color); # Set the layer mode before merging the floating layer back # onto the drawable with gimp_floating_sel_anchor(). $floating_layer->set_mode(OVERLAY_MODE); # Calls gimp_layer_set_mode $floating_layer->anchor; # Calls gimp_floating_sel_anchor # Update the drawable with the changes. $drawable->update(0, 0, $drawable->width, $drawable->height); gimp_undo_push_group_end($img); # End the undo group # Return the new image if "work on copy" is true, otherwise undef return ($return_val); } # Embedded POD documentation follows =head1 NAME Apply Tint =head1 HELP Applies a colored tint to an image (works best on grayscale images). The end result is kind of a sepia-tone or duotone effect. =head1 AUTHOR Shawn P. Wallace =head1 COPYRIGHT (c) 2001 The Institute for Folk Computing =head1 DATE 2001-09-12