Gimp/plug-ins/perl/examples/Create_Images

109 lines
3.1 KiB
Text
Raw Normal View History

1998-10-23 06:34:08 -07:00
#!/usr/bin/perl
1999-12-01 20:55:44 -08:00
# THIS IS OUTDATED AND WILL NOT RUN WITH CURRENT GIMP VERSIONS!
1998-10-23 06:34:08 -07:00
# Send to me by Jason van Zyl <jason@bookshelf.ca>
# see the accompanying file image_list
# This is just a complete rip-off of Marc's first plug-in.
# Doesn't really do much, but hey, we'll get there!
use Gimp;
$black = "#000000";
$white = "#FFFFFF";
#$font = "frutiger";
$font = "engraver";
# enable example mode... if disabled, it will write out some logos, and not
# wont' display anything.
$example = 1;
# set trace level to watch functions as they are executed
1999-02-22 13:51:18 -08:00
#Gimp::set_trace(TRACE_NAME);
1998-10-23 06:34:08 -07:00
# convert image to indexed
# and automatically save it as interlaced gif.
sub index_and_save($$) {
my($img,$path)=@_;
gimp_image_flatten($img);
gimp_convert_indexed_palette($img,1,0,32,"");
file_gif_save(RUN_NONINTERACTIVE,$img,-1,$path,$path,1,0,0,0) unless $example;
}
sub Create_Image {
my($text,$size)=@_;
my($Image,$Text_Layer,$Background_Layer,$Width,$Height);
# Let's see if we can plug a little daemon in here.
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
$border = 10;
$size = 100;
$Background_Colour = $white;
$Text_Colour = $black;
# 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(256,256,RGB);
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
# Create a layer for the text.
$Text_Layer = gimp_text($Image,-1,0,0,$text,$border,1,$size,PIXELS,"*",$font,"*","*","*","*");
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
# Do the fun stuff with the text.
gimp_palette_set_background($Text_Colour);
gimp_layer_set_preserve_trans($Text_Layer, TRUE);
#gimp_edit_fill($Image, $Text_Layer);
# Now figure out the size of $Text_Layer.
$Width = gimp_drawable_width($Text_Layer);
$Height = gimp_drawable_height($Text_Layer);
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
# Create a layer for the background based on the size of the text.
$Background_Layer = gimp_layer_new($Image,$Width,$Height,RGB_IMAGE,"Background",100,NORMAL_MODE);
# Resize the $Image based on size of text.
gimp_image_resize($Image,$Width,$Height,0,0);
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
# Add the $Background_Layer to the image.
gimp_image_add_layer($Image, $Background_Layer, 1);
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
# Set the background colour and fill it in with that colour.
gimp_palette_set_background($Background_Colour);
gimp_drawable_fill($Background_Layer,BG_IMAGE_FILL);
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
#index_and_save ($Image, "/tmp/${text}_" . ".gif");
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
gimp_display_new ($Image) if $example;
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
#gimp_image_delete($Image) unless $example;
}
sub extension_create_images {
#Get our list of strings that we want to make images with.
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
$Image_Directory = "/tmp";
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
$active = 0;
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
open(IMAGE_LIST, "/tmp/image_list");
1999-05-03 12:29:05 -07:00
1998-10-23 06:34:08 -07:00
while( <IMAGE_LIST> ) {
chop;
Create_Image (split(/\|/));
}
}
sub query {
gimp_install_procedure("extension_create_images", "a test extension in perl",
"try it out", "Marc Lehmann", "Marc Lehmann", "1997-02-06",
1999-11-29 13:46:18 -08:00
N_"<Toolbox>/Xtns/Create_Images", "*", PROC_EXTENSION,
1998-10-23 06:34:08 -07:00
[[PARAM_INT32, "run_mode", "Interactive, [non-interactive]"]], []);
}
sub net {
extension_create_images;
}
1999-02-22 13:51:18 -08:00
exit main;
1998-10-23 06:34:08 -07:00