#!/usr/bin/perl -w # # This is a Perl-Fu GIMP plug-in script that should take user-specified # files (globbing allowed), and put a user-specified watermark text signature # on each one. # # Nadim Nakhleh 3/17/01 # use Gimp qw(:auto N_); use Gimp::Fu; use Gimp::Util; # Register plug-in register("watermark_images_1", "Watermarks the specified images with a user-specified text string", "Just enter in your filenames (standard Unix shell wildcards apply) and your parameters (text, font, placement), and it's off to the races. Just make sure that you run this ON A COPY OF YOUR FILES, not the originals, as it overwrites the original versions. You have been warned. It's not my fault.", "Nadim Nakhleh", "(c) Nadim Nakhleh", "3/17/01", N_"/Xtns/Perl-Fu/Watermark Images 1", "*", [ [ PF_STRING, "files", "File name(s) (* is allowed)", "" ], [ PF_FONT, "font", "Font Name", "-*-helvetica-bold-r-normal-*-*-*-*-*-p-*-iso8859-1" ], [ PF_STRING, "text", "Enter the text to be signed", "www.nakhleh.net"], [ PF_RADIO, "location", "Select watermark location", 3, [ "bottom left" => 1, "bottom_center" => 2, "bottom_right" => 3 ] ], ], \&do_watermark_images_1); sub do_watermark_images_1 { my($files, $font, $text, $location) = @_; my($file, $img, $drw); my($txtlayer, $flayer, $xoffset, $yoffset); my($lwidth, $lheight); # Walk through the filenames foreach $file (glob($files)) { # Load the file $img = gimp_file_load(RUN_NONINTERACTIVE, $file, $file); $drw = gimp_image_active_drawable($img); # # Watermark the image # # Generate new dynamic text layer $txtlayer = plug_in_dynamic_text(RUN_NONINTERACTIVE, $drw, # Pass in drawable $text, # Pass in text string 1, # Set anti-aliasing ON 1, # Set alignment to CENTER 0, # Set rotation to 0 0, # Set line-spacing to 1 [255, 255, 255], # Set color to WHITE $location, # Pass in location $font); # Pass in font # Add a little buffer around the dynamic text layer...it tends to cut it # too close on the top and left sides $lwidth = gimp_drawable_width($txtlayer); $lheight = gimp_drawable_height($txtlayer); gimp_layer_resize($txtlayer, $lwidth + 4, $lheight + 4, 4, 4); # Get bump map layer offsets, as the non-interactive bump map command doesn't # seem to want to calculate them for me automatically ($xoffset, $yoffset) = gimp_drawable_offsets($txtlayer); $xoffset *= -1; $yoffset *= -1; # Bump map original layer with text layer plug_in_bump_map(RUN_NONINTERACTIVE, $drw, # Pass in drawable $txtlayer, # Pass in text layer for bump map 135, # Azimuth 45, # Elevation 3, # Depth $xoffset, # X offset $yoffset, # Y offset 0, # Waterlevel 0, # Ambient 1, # Compensate for darkening 0, # Don't invert 0); # Use LINEAR map # Drop opacity on text layer to 10% (so you can still something in # dark regions) gimp_layer_set_opacity($txtlayer, 10); # Flatten the result $flayer = gimp_image_flatten($img); # # End inserted watermarking code # # Save the new image file_jpeg_save(RUN_NONINTERACTIVE, $flayer, $file, $file, .75, 0, 1, 0, "A NadimWare Original", 0, 1, 0, 0); # Don't forget to clean up memory - Currently broken...I can't figure # out what GIMP is doing here at all...appears to be a bug in GIMP?? # Both lines below were tried (not together, of course), both produce # unexpected (to me) errors... # I dunno... $img->delete(); #gimp_image_remove_layer($img, $img->get_active_layer()); } # Don't have an image, but make Gimp happy... return undef; } exit main;