On Thu, Feb 08, 2001 at 07:29:59PM +0100, Jonathan Gift wrote:
> With the cal 2001 command I can get the year's calendar displayed on a
> terminal or shot to a file. Q: How can I use that as background, as in
> paste?
Since I'm bored I decided to write a little Perl-Fu script to do this.
It's probably not very robust or elegant or whatever, but it works :-)
If anyone knows a better way to get the font size, drop me a line 'cause
this is ugly in my solution...
cheers,
.roel
#!/usr/bin/perl -w
# Gimp Perl-Fu script to make a calendar.
# Roel Vanhout, [EMAIL PROTECTED], 20010208
use Gimp;
use Gimp::Fu;
sub makeimage {
my($mon,$year,$font,$fgcolor,$bgcolor, $border) = @_;
if($mon eq "") {
$text = `cal $year`;
} else {
$text = `cal $mon $year`;
}
my @array = split/-/, $font;
my $size = $array[8];
$size /= 10;
my ($width, $height, $ascent, $descent) =
Gimp->gimp_text_get_extents_fontname($text, $size, 0, $font);
my $image = Gimp->gimp_image_new($width + $border * 2, $height +
$border * 2, RGB);
my $background = Gimp->gimp_layer_new($image, $width + $border * 2,
$height + $border * 2, RGB, "Background", 100, NORMAL_MODE);
Palette->set_background($bgcolor);
$background->fill(BG_IMAGE_FILL);
Gimp->gimp_image_add_layer($background, 1);
Palette->set_foreground($fgcolor);
my $textlayer = Gimp->gimp_text_fontname($background, $border,
$border, $text, -1, 1, $size, 0, $font);
Gimp->gimp_image_resize($image, $textlayer->width + $border * 2,
$textlayer->height + $border * 2, 0, 0);
Gimp->gimp_layer_resize($background, $textlayer->width + $border *
2, $textlayer->height + $border * 2, 0, 0);
Gimp->gimp_floating_sel_anchor($textlayer);
return $image;
}
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
register "makeimage",
"Makes a calendar",
"This scipt makes a calendar.",
"Roel Vanhout",
"roel\@2e-systems.com", # @ must be written as \@ in a perl
string
"0.0",
"<Toolbox>/Xtns/Script-Fu/Misc/Calendarbutton",
"",
[
[PF_INT, 'month', 'The month you want a calendar for. Leave
empty if you want a full year.', $mon +1],
[PF_INT, 'year', 'The year you want a calendar for. Leave
empty if you want a full year.', $year+ 1900],
[PF_FONT, 'font', 'The font you want to use',
"-misc-fixed-medium-r-normal-*-*-200-*-*-c-*-iso10646-1"],
[PF_COLOR, 'fgcolor', 'The foreground color',
[255,255,255]],
[PF_COLOR, 'bgcolor', 'The background color', [0,0,0]],
[PF_INT, 'border', 'The border you want around the
calendar', 10]
],
\&makeimage;
exit main;