#!/usr/local/bin/perl
# Generate an image strip of ASCII characters.

use Gimp ":auto";
use Gimp::Fu;

sub basic_logo {
    my($font, $bgcolor, $fgcolor) = @_;

    # Generate the text - all ASCII chars from 33 - 126.
    my $text = "";
    for($i = 33; $i <= 126; $i++) {
      $text .= chr($i);
    }

    # Create a new image of an arbitrary size.
    $img = gimp_image_new(100, 100, RGB);

    # Create a new layer for the background of arbitrary size, and
    # add it to the image
    my $background = gimp_layer_new($img, 100, 100,
				    RGB, "Background", 100,
				    NORMAL_MODE);
    gimp_image_add_layer($background, 1);

    # Choose color of text
    gimp_palette_set_foreground($fgcolor);

    # Create the text layer. Using -1 as the drawable creates a new layer.
    my $text_layer = gimp_text_fontname($img, -1, 0, 1, $text,
					0, 0,
					xlfd_size($font), $font);

    # Get size of the text drawable and resize the image and the
    # background layer to this size.
    my($width, $height) = ($text_layer->width, $text_layer->height);
    $height++;
    gimp_image_resize($img, $width, $height, 0, 0);
    gimp_layer_resize($background, $width, $height, 0, 0);

    # Fill the background layer now when it has the right size.
    gimp_palette_set_background($bgcolor);
    gimp_edit_fill($background, BG_IMAGE_FILL);

    return $img;
}

# register the script
register "ascii", "ascii", "ascii",
    "Peter Gammie", "Peter Gammie",
    "2002-02-03",
    "<Toolbox>/Xtns/Perl-Fu/Alphabet",
    "*",
    [
     [PF_FONT,   "font",     "font",   "-dosemu-vga-medium-r-normal-*-17-*-*-*-p-*-ibm-cp437"],
     [PF_COLOR,  "bg_color", "Background color", [0,0,0]],
     [PF_COLOR,  "fg_color", "Foreground color", [255,255,255]],
    ],
    \&basic_logo;

# Handle over control to gimp
exit main();
