1#!/usr/bin/perl -w
2
3use Gimp;
4use Gimp::Fu;
5use strict;
6use warnings;
7
8podregister {
9  $thresh /= 255;
10  $image = $image->duplicate if $new;
11  $image->undo_group_start;
12  $drawable = $image->flatten;
13  if ($alpha) {
14    $drawable->add_alpha;
15    Gimp::Context->set_sample_threshold($thresh);
16    $image->select_color(CHANNEL_OP_REPLACE,$drawable,$bg);
17    $drawable->edit_cut if $image->selection_bounds;
18  }
19  $drawable->autocrop if $autocrop;
20  $image->convert_indexed (2, 0, $colours, 0, 0, '') if $colours;
21  $image->undo_group_end;
22  if ($new) {
23    $image->clean_all;
24    eval { Gimp::Display->new($image) };
25  }
26  return $image
27};
28exit main;
29__END__
30
31=head1 NAME
32
33webify - Make an image suitable for the web
34
35=head1 SYNOPSIS
36
37<Image>/Filters/Web/Webify...
38
39=head1 DESCRIPTION
40
41Flattens an image, makes the background transparent, converts it to
42indexed and then crops it to the right size. Useful to save small &
43transparent gifs from a higher-quality source.
44
45=head1 PARAMETERS
46
47  [PF_BOOL, "new", "Create a new image", 1],
48  [PF_BOOL, "alpha", "Make transparent", 1],
49  [PF_COLOUR, "bg", "Background colour to use for transparency", "white"],
50  [PF_SLIDER, "thresh", "Threshold to use for background detection", 100, [0, 255, 1]],
51  [PF_INT32, "colours", "How many colours to use (0 = don't convert to indexed)", 32],
52  [PF_BOOL, "autocrop", "Autocrop at end", 1],
53
54=head1 RETURN VALUES
55
56  [PF_IMAGE, 'image', 'Output image']
57
58=head1 IMAGE TYPES
59
60RGB*, GRAY*
61
62=head1 AUTHOR
63
64Marc Lehmann
65
66=head1 DATE
67
681.0
69
70=head1 LICENSE
71
72Marc Lehmann
73
74Distributed under the same terms as Gimp-Perl.
75