#!/usr/bin/perl -w # # This is a Perl-Fu GIMP plug-in script that should take user-specified # files (globbing allowed), and generate from each one a web-sized and a # thumbnail-sized version. # # Nadim Nakhleh 11/23/00 # use Gimp qw(:auto N_); use Gimp::Fu; use Gimp::Util; # Register plug-in register("gen_websized_images", "Generates large web-sized images, and thumbnail images, from high resolution source images", "Sorry buddy...I can barely help myself right now...", "Nadim Nakhleh", "(c) Nadim Nakhleh", "11/24/00", N_"/Xtns/Perl-Fu/Generate Websized Images", "*", [ [ PF_STRING, "files", "File name(s) (* is allowed)", "" ], [ PF_INT, "large_edge_size", "The length of the long edge (in pixels) of the large image to be created", 700 ], [ PF_STRING, "large_suffix", "The suffix to add to the new large image created", "_l" ], [ PF_INT, "thumb_edge_size", "The length of the long edge (in pixels) of the thumbnail image to be created", 160 ], [ PF_STRING, "thumb_suffix", "The suffix to add to the new thumbnail image created", "_t" ] ], \&gen_websized_images); sub gen_websized_images { my($files, $lsize, $lsuf, $tsize, $tsuf) = @_; my($file, $img, $drw, $x0, $y0, $x1, $y1, $x2, $y2); my($newfile); foreach $file (glob($files)) { if ($file =~ /$lsuf\.jpg/ or $file =~ /$tsuf\.jpg/) { print "File \"$file\" appears to be processed already...skipping\n"; next; } # Load the file $img = gimp_file_load(RUN_NONINTERACTIVE, $file, $file); $drw = $img->active_drawable(); # # Generate large image # # Get dimensions ($x0, $y0) = ($x1, $y1) = ($img->width(), $img->height()); # Compute size of new image if ($x0 > $y0) { if ($x0 > $lsize) { $x1 = $lsize; $y1 = int($y0 * ($lsize / $x0) + 0.5); } } else { if ($y0 > $lsize) { $y1 = $lsize; $x1 = int($x0 * ($lsize / $y0) + 0.5); } } # If we are going to resize if ($x0 != $x1 and $y0 != $y1) { # Resize $img->scale($x1, $y1); # Save the new image $newfile = $file; $newfile =~ s/(.*)\..*/$1${lsuf}.jpg/; file_jpeg_save(RUN_NONINTERACTIVE, $img, $drw, $newfile, $newfile, .75, 0, 1, 0, "A NadimWare Original", 0, 1, 0, 0); } # # Generate thumbnail image # # Get dimensions ($x2, $y2) = ($x1, $y1); # Compute size of new image if ($x1 > $y1) { if ($x1 > $tsize) { $x2 = $tsize; $y2 = int($y1 * ($tsize / $x1) + 0.5); } } else { if ($y1 > $tsize) { $y2 = $tsize; $x2 = int($x1 * ($tsize / $y1) + 0.5); } } # If we are going to resize if ($x1 != $x2 and $y1 != $y2) { # Resize $img->scale($x2, $y2); # Save the new image $newfile = $file; $newfile =~ s/(.*)\..*/$1${tsuf}.jpg/; file_jpeg_save(RUN_NONINTERACTIVE, $img, $drw, $newfile, $newfile, .75, 0, 1, 0, "A NadimWare Original", 0, 1, 0, 0); } # Don't forget to clean up memory $img->delete(); } # Don't have an image, but make Gimp happy... return undef; } exit main;