1: #!/usr/local/bin/perl
2:
3: use Gimp qw( :auto );
4: use Gimp::Fu;
5:
6: sub horiz_cat {
7: my($img1, $drw1, $drw2) = @_;
8:
9: # Get image 2
10: $img1 = $drw1->image();
11:
12: my $img2 = gimp_drawable_image($drw2);
13: my($w1, $h1) = ($drw1->width, $drw1->height);
14: my($w2, $h2) = ($drw2->width, $drw2->height);
15:
16: # The new height is the maximum height of the images
17: my $hmax = $h1 > $h2 ? $h1 : $h2;
18:
19: # Create an undo group
20: gimp_undo_push_group_start($img1);
21:
22: # Resize the drawable layer to make room for the img
23: gimp_image_resize($img1, $w1+$w2, $hmax, 0, ($hmax-$h1)/2);
24: gimp_layer_resize($drw1, $w1+$w2, $hmax, 0, ($hmax-$h1)/2);
25:
26: # Copy $drawable2 and paste it into the new space of $drawable1
27: # select all of img2
28: $img2->selection_all();
29: $drw2->edit_copy();
30:
31: # make a selection in img 1 where $drw2 is to be pasted
32: gimp_rect_select($img1, $w1, ($hmax-$h2)/2, $w2, $h2, 0,0,0);
33:
34: # paste and then anchor it
35: my $floating_layer = gimp_edit_paste($drw1, 0);
36: gimp_floating_sel_anchor($floating_layer);
37:
38: # Close the undo group
39: gimp_undo_push_group_end($img1);
40:
41: # Update the display
42: gimp_displays_flush();
43:
44: return undef;
45: }
46:
47: # register the script
48: register "horiz_cat", "Horizontal concat", "Horizontal Concat",
49: "Dov Grobgeld", "Dov Grobgeld", "2003-05-04",
50: "<Image>/Perl-Fu/Tutorial/Horizontal Concat",
51: "*",
52: [[PF_DRAWABLE, "drawable", "Drawable to concatinate", undef]],
53: \&horiz_cat;
54:
55: exit main();
|