#!/usr/bin/perl

use Gimp qw(:auto __ N_);
use Gimp::Fu;
use Gimp::Util;

podregister {
  Gimp::Context->push();
  $drawable->has_alpha or die __"You can't run this script without an ALPHA CHANNEL!!";
  my $test = 0;
  $test = $drawable->type_with_alpha;
  if ($test == 5) {
    die __"You can't run this script with an INDEXED image!!";
  } elsif ($test == 3) {
    gimp_image_convert_rgb ($image);
  }
  my $img = gimp_image_new (100, 100, RGB_IMAGE);
  $drawable->get_image->selection_all;
  $drawable->edit_copy;
  gimp_selection_none ($image);
  my $layer=$img->layer_new($drawable->width,$drawable->height,$image->layertype(1), __"Text", 100, NORMAL_MODE);
  $layer->drawable_fill(TRANSPARENT_FILL);
  $img->insert_layer($layer,0,0);
  $layer->edit_paste(0)->floating_sel_anchor;
  $img->resize($drawable->width,$drawable->height, 0, 0);
  $img->select_item(CHANNEL_OP_REPLACE, $layer);
  $img->selection_invert;
  Gimp::Context->set_background ([255, 255, 255]);
  gimp_edit_fill ($layer, BACKGROUND_FILL);
  gimp_selection_none ($img);
  gimp_invert ($layer);
  plug_in_gauss_rle ($layer, 2.0, 1, 1);
  my $bump_lay = $img->layer_new($img->width,$img->height, RGBA_IMAGE, __"Bumpmap", 100, NORMAL_MODE);
  $bump_lay->drawable_fill(BACKGROUND_FILL);
  $img->insert_layer($bump_lay,0,0);
  if ($rad_tog == 1) {
    Gimp::Context->set_pattern ($pattern);
    gimp_edit_bucket_fill ($bump_lay, PATTERN_BUCKET_FILL, NORMAL_MODE, 100, 0, 0, 0, 0);
  } else {
    Gimp::Context->set_background ($txt_col);
    gimp_edit_fill ($bump_lay, BACKGROUND_FILL);
  }
  $bump_lay->bump_map($layer, 110.0, 45.0, 4, 0, 0, 0, 0, 1, 0, 0);
  $pattern_mask = $bump_lay->create_mask(ADD_ALPHA_MASK);
  $bump_lay->add_mask($pattern_mask);
  gimp_selection_all ($img);
  gimp_edit_copy ($layer);
  $float = gimp_edit_paste ($pattern_mask, 0);
  gimp_floating_sel_anchor ($float);
  $pattern_mask->levels(0, 0, 77, 0.91, 0, 255);
  $bump_lay->remove_mask(MASK_APPLY);
  gimp_invert ($layer);
  gimp_image_flatten ($img);
  gimp_image_convert_indexed ($img, 0, MAKE_PALETTE, 256, 0, 0, "");
  my $new = gimp_image_get_active_drawable ($img);
  gimp_layer_add_alpha ($new);
  gimp_image_select_color ($img, CHANNEL_OP_ADD, $new, [255, 255, 255]);
  gimp_edit_clear ($new);
  gimp_selection_none ($img);
  return;
};
exit main;
__END__

=head1 NAME

make_trans_logos - A script to get transparent beveled logos

=head1 SYNOPSIS

<Image>/Filters/Web/Transparent Logo...

=head1 DESCRIPTION

This script aims to produce a transparent logo in an indexed image
which is ready to be saved in .gif format. If you need a transparent
image containing a logo for your web page, just apply this script over
a drawable with an alpha channel in RGB or GRAY mode.

You can choose between colour and pattern fill of your text.

As an input, you need to have an image that has an alpha channel,
and isn't 100% opaque - it's really designed to work with a text layer.
It will then make a "logo" out of your non-white sections of the image
and index it.  The original image is untouched.

=head1 PARAMETERS

 [PF_RADIO, 'rad_tog', 'Use a colour or a pattern for text', 0,
    [Colour => 0, Pattern => 1]],
 [PF_PATTERN, 'pattern', "Text pattern", "Wood #1"],
 [PF_COLOUR, 'txt_col', "Text color", [69, 88, 211]],

=head1 IMAGE TYPES

*

=head1 HISTORY

  12/5/03: <sjburges@gimp.org>
   s/gimp_convert/gimp_image_convert/

=head1 AUTHOR

Michele Gherlone <mikem@enet.it>

=head1 DATE

20000123

=head1 LICENSE

(c) 2000 M. Gherlone

Distributed under unknown licensing terms.
