GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit 7f520416 authored by Marc Lehmann's avatar Marc Lehmann

see plug-ins/perl/Changes

parent 54c00f32
......@@ -5,6 +5,7 @@ Revision history for Gimp-Perl extension.
- moved constants from Gimp.xs and extradefs.h to Gimp.pm, where
they belong (either there or into Gimp.xs)
- added view3d.pl to examples (untested)
- Gimp::Util is reborn (give it a try and contribute!)
1.05 Fri Dec 18 22:05:25 CET 1998
- some 5.006 compatibility fixes
......
......@@ -497,7 +497,7 @@ create hybrid (networked & libgimp) scripts as well.
=item *
Use either a plain pdb (scheme-like) interface or nice object-oriented
syntax, i.e. "gimp_layer_new(600,300,RGB)" is the same as "new Image(600,300,RGB)"
syntax, i.e. "gimp_image_new(600,300,RGB)" is the same as "new Image(600,300,RGB)"
=item *
Gimp::Fu will start The Gimp for you, if it cannot connect to an existing
......@@ -523,13 +523,13 @@ callback procedures do not poass return values to The Gimp.
All plug-ins (and extensions etc.) _must_ contain a call to C<Gimp::main>.
The return code should be immediately handed out to exit:
C<exit main;> # Gimp::main is exported by default.
exit main; # Gimp::main is exported by default.
Before the call to C<Gimp::main>, I<no> other PDB function must be called.
In a Gimp::Fu-script, you should call C<Gimp::Fu::main> instead:
C<exit main;> # Gimp::Fu::main is exported by default as well.
exit main; # Gimp::Fu::main is exported by default as well.
This is similar to Gtk, Tk or similar modules, where you have to call the
main eventloop.
......@@ -566,7 +566,7 @@ If you C<die> within the callback, the error will be reported to The Gimp
=item net ()
this is called when the plug-in is not started directly from within the
Gimp, but instead from the I<Net-Server> (the perl network server extension you
Gimp, but instead from the B<Net-Server> (the perl network server extension you
hopefully have installed and started ;)
=back
......
##############################################################################
# [12/23/98] Tels v0.0.1 http://bloodgate.com/art/gimp/
=head1 NAME
Gimp::Utils - some handy routines for Gimp.Perl users
=head1
use Gimp;
use Gimp::Util;
=head1 DESCRIPTION
gimp.perl is nice, but when you have to write everytime 10 lines just to get
some simple functions done, it very quickly becomes tedious :-/
This module tries to define some functions that aim to automate frequently
used tasks. If you want to add a function just mail the author of the
Gimp-Perl extension (see below).
In Gimp-Perl (but not in Gimp as seen by the enduser) it is possible to have
layers that are NOT attached to an image. This is, IMHO a bad idea, you end up
with them and the user cannot see them or delete them. So we always attach our
created layers to an image here, too avoid memory leaks and debugging times.
These functions preserve the current settings like colors.
=head1 FUNCTIONS
=over 4
=cut
package Gimp::Util;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
layer_create
text_draw
image_create_text
layer_add_layer_as_mask
);
#@EXPORT_OK = qw();
$VERSION=1.000;
use Gimp;
##############################################################################
=pod
=item C<get_state ()>, C<set_state state>
C<get_state> returns a scalar representing most of gimps global state (at the
moment foreground colour and background colour). The state can later be
restored by a call to C<set_state>. This is ideal for library functions such
as the ones used here, at least when it includes more state in the future.
=cut
sub get_state() {
[Palette->get_foreground,Palette->get_background];
}
sub set_state($) {
Palette->set_foreground($_->[0]);
Palette->set_background($_->[1]);
}
##############################################################################
=pod
=item C<layer_create image,name,color,pos>
create a colored layer, insert into image and return layer
=cut
# [12/23/98] v0.0.1 Tels - First version
sub layer_create {
my ($image,$name,$color,$pos) = @_;
my $layer;
my $tcol; # scratch color
# create a colored layer
$layer = gimp_layer_new ($image,gimp_image_width($image),
gimp_image_height($image),
RGB_IMAGE,$name,100,NORMAL_MODE);
$tcol = gimp_palette_get_background ();
gimp_palette_set_background ($color);
gimp_drawable_fill ($layer,BG_IMAGE_FILL);
gimp_image_add_layer($image, $layer, $pos);
gimp_palette_set_background ($tcol); # reset
$layer;
}
##############################################################################
=pod
=item C<text_draw image,layer,text,font,size,fgcolor>
Create a colored text, draw over a background, add to img, ret img.
=cut
# [12/23/98] v0.0.1 Tels - First version
sub text_draw {
my ($image,$layer,$text,$font,$size,$fgcolor) = @_;
my ($bg_layer,$text_layer);
my $tcol; # temp. color
warn ("text string is empty") if ($text eq "");
warn ("no font specified, using default") if ($font eq "");
$font = "Helvetica" if ($font eq "");
$tcol = gimp_palette_get_foreground ();
gimp_palette_set_foreground ($fgcolor);
# Create a layer for the text.
$text_layer = gimp_text($image,-1,0,0,$text,10,1,$size,
PIXELS,"*",$font,"*","*","*","*");
# Do the fun stuff with the text.
gimp_layer_set_preserve_trans($text_layer, FALSE);
if ($resize == 0)
{
# Now figure out the size of $image
$width = gimp_image_width($text_layer);
$height = gimp_image_height($text_layer);
# and cut text layer
}
else
{
}
# add text to image
gimp_image_add_layer($image, $text_layer, $pos);
# merge white and text
gimp_image_merge_visible_layers ($image,1);
# cleanup the left over layer (!)
gimp_layer_delete($text_layer);
$layer;
}
##############################################################################
=pod
=item C<image_create_text text,font,size,fgcolor,bgcolor>
Create an image, add colored text layer on a background layer, return img.
=cut
# [12/23/98] v0.0.1 Tels - First version
sub image_create_text {
my ($text,$font,$size,$fgcolor,$bgcolor) = @_;
my $tcol; # temp. color
my $text_layer;
my $bg_layer;
my $image;
warn ("text string is empty") if ($text eq "");
warn ("no font specified, using default") if ($font eq "");
$font = "Helvetica" if ($font eq "");
# create an image. We'll just set whatever size here because we want
# to resize the image when we figure out how big the text is.
$image = gimp_image_new(64,64,RGB); # don't waste too much resources ;-/
$tcol = gimp_palette_get_foreground ();
gimp_palette_set_foreground ($fgcolor);
# Create a layer for the text.
$text_layer = gimp_text($image,-1,0,0,$text,10,1,$size,
PIXELS,"*",$font,"*","*","*","*");
gimp_palette_set_foreground ($tcol);
gimp_layer_set_preserve_trans($text_layer, FALSE);
# Resize the image based on size of text.
gimp_image_resize($image,gimp_drawable_width($text_layer),
gimp_drawable_height($text_layer),0,0);
# create background and merge them
$bg_layer = layer_create ($image,"text",$bgcolor,1);
gimp_image_merge_visible_layers ($image,1);
# return
$image;
}
##############################################################################
=pod
=item C<layer_add_layer_as_mask image,layer,layermask>
Take a layer and add it as a mask to another layer, return mask.
=cut
# [12/23/98] v0.0.1 Tels - First version
sub layer_add_layer_as_mask {
my ($image,$layer,$layer_mask) = @_;
my $mask;
gimp_selection_all ($image);
gimp_edit_copy ($image,$layer_mask);
gimp_layer_add_alpha ($layer);
$mask = gimp_layer_create_mask ($layer,0);
gimp_edit_paste ($image,$mask,0);
gimp_floating_sel_anchor(gimp_image_floating_selection($image));
gimp_image_add_layer_mask ($image,$layer,$mask);
$mask;
}
# EOF, needed for package?
# Sure, consider a package just another kind of function, and
# require/use etc. check for a true return value
1;
=pod
=head1 AUTHOR
Various, version 1.000 written mainly by Tels (http://bloodgate.com/). The author
of the Gimp-Perl extension (contact him to include new functions) is Marc
Lehmann <pcg@goof.com>
......@@ -32,6 +32,7 @@ Gimp/Fu.pm
Gimp/PDL.pm
Gimp/Pixel.pod
Gimp/UI.pm
Gimp/Util.pm
examples/PDB
examples/alpha2color.pl
examples/tex-to-float
......
......@@ -160,6 +160,7 @@ WriteMakefile(
'Gimp/UI.pm' => '$(INST_LIBDIR)/Gimp/UI.pm',
'Gimp/Net.pm' => '$(INST_LIBDIR)/Gimp/Net.pm',
'Gimp/PDL.pm' => '$(INST_LIBDIR)/Gimp/PDL.pm',
'Gimp/Util.pm' => '$(INST_LIBDIR)/Gimp/Util.pm',
},
'LIBS' => [''],
'INC' => "$CPPFLAGS $CFLAGS $GIMP_INC_NOUI $DEFS",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment