File: webify

package info (click to toggle)
libgimp-perl 2.0.dfsg-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,112 kB
  • ctags: 462
  • sloc: perl: 10,026; sh: 207; ansic: 207; makefile: 70
file content (56 lines) | stat: -rwxr-xr-x 1,579 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/opt/bin/perl

eval 'exec /opt/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

use Gimp;
use Gimp::Fu;

#Gimp::set_trace(TRACE_ALL);

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",
         N_"<Image>/Filters/Web/Webify...",
         "RGB*, GRAY*",
         [
          [PF_BOOL,	"new",		"create a new image?", 1],
          [PF_BOOL,	"transparent",	"make transparent?", 1],
          [PF_COLOUR,	"bg_color",	"the background colour to use for transparency", "white"],
          [PF_SLIDER,	"threshold",	"the threshold to use for background detection", 3, [0, 255, 1]],
          [PF_INT32,	"colors",	"how many colours to use (0 = don't convert to indexed)", 32],
          [PF_BOOL,	"autocrop",	"autocrop at end?", 1],
         ],
         sub {
   my($img,$drawable,$new,$alpha,$bg,$thresh,$colours,$autocrop)=@_;

   $img = $img->duplicate if $new;

   eval { $img->undo_group_start };

   $drawable = $img->flatten;

   if ($alpha) {
      $drawable->add_alpha;
      $drawable->by_color_select($bg,$thresh,CHANNEL_OP_REPLACE,1,0,0,0);
      $drawable->edit_cut if $img->selection_bounds;
   }
   Plugin->autocrop($drawable) if $autocrop;
   $img->convert_indexed (2, 0, $colours, 0, 0, '') if $colours;

   eval { $img->undo_group_end };

   $new ? ($img->clean_all, $img) : ();
};

exit main;

=head1 LICENSE

Copyright Marc Lehman.
Distrubuted under the same terms as Gimp-Perl.

=cut