Gimp/plug-ins/perl/examples/webify.pl

48 lines
1.4 KiB
Perl
Raw Normal View History

1999-02-19 03:56:13 -08:00
#!/usr/bin/perl
1998-10-23 06:34:08 -07:00
use Gimp;
use Gimp::Fu;
1999-02-22 13:51:18 -08:00
#Gimp::set_trace(TRACE_ALL);
1998-10-23 06:34:08 -07:00
register "webify",
"Make an image suitable for the web",
"This plug-in converts the image to indexed, with some extra options",
"Marc Lehmann",
"Marc Lehmann",
"1.0",
1999-11-29 13:46:18 -08:00
N_"<Image>/Filters/Web/Webify",
1998-10-23 06:34:08 -07:00
"RGB*, GRAY*",
[
[PF_BOOL, "new", "create a new image?", 1],
[PF_BOOL, "transparent", "make transparent?", 1],
1999-03-23 13:21:11 -08:00
[PF_COLOUR, "bg_color", "the background colour to use for transparency", "white"],
1998-10-23 06:34:08 -07:00
[PF_SLIDER, "threshold", "the threshold to use for background detection", 3, [0, 255, 1]],
1999-03-23 13:21:11 -08:00
[PF_INT32, "colors", "how many colours to use (0 = don't convert to indexed)", 32],
1998-10-23 06:34:08 -07:00
[PF_BOOL, "autocrop", "autocrop at end?", 1],
],
sub {
my($img,$drawable,$new,$alpha,$bg,$thresh,$colours,$autocrop)=@_;
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
$img = $img->channel_ops_duplicate if $new;
1999-05-03 12:29:05 -07:00
1999-10-24 13:46:19 -07:00
eval { $img->undo_push_group_start };
1999-03-12 12:37:06 -08:00
1998-10-23 06:34:08 -07:00
$drawable = $img->flatten;
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
if ($alpha) {
$drawable->add_alpha;
1999-07-28 14:23:35 -07:00
$drawable->by_color_select($bg,$thresh,REPLACE,1,0,0,0);
1998-10-23 06:34:08 -07:00
$drawable->edit_cut if $img->selection_bounds;
}
1998-12-18 18:53:19 -08:00
Plugin->autocrop($drawable) if $autocrop;
1999-10-24 13:46:19 -07:00
$img->convert_indexed (2, 0, $colours, 0, 0, '') if $colours;
1999-05-03 12:29:05 -07:00
1999-10-24 13:46:19 -07:00
eval { $img->undo_push_group_end };
1999-05-03 12:29:05 -07:00
1999-05-26 13:23:32 -07:00
$new ? ($img->clean_all, $img) : ();
1998-10-23 06:34:08 -07:00
};
exit main;