mirror of https://github.com/GNOME/gimp.git
see plug-ins/perl/Changes
This commit is contained in:
parent
5d929fb51b
commit
9ef96aeabf
plug-ins/perl/examples
|
@ -4,36 +4,53 @@
|
|||
# this sort of thing. Personally I'll probably only run it to test and
|
||||
# put up a demo image.
|
||||
|
||||
# Since updated a couple times by others, and intgrated by me:
|
||||
#
|
||||
# Bruce Miller (fixed to accomdate 1.1.x changes)
|
||||
# Brendon and Wendy Humphrey <brendy@swipnet.se> (progress bar, nice comments)
|
||||
#
|
||||
# If you have more additions, etc please don't hesitate to send them in!
|
||||
|
||||
|
||||
use Gimp;
|
||||
use Gimp::Fu;
|
||||
use Gimp::Util;
|
||||
|
||||
# Uncomment if you want to see everything that's going on.
|
||||
# Gimp::set_trace(TRACE_ALL);
|
||||
|
||||
sub get_vguides { # get back an ordered set of vertical guides
|
||||
#
|
||||
# Generates an ordered list of all existing vertical guides.
|
||||
#
|
||||
|
||||
sub get_vguides {
|
||||
my ($img)=@_;
|
||||
$i=0;
|
||||
my @vguides;
|
||||
while ($i=$img->find_next_guide($i)) {
|
||||
if ($img->get_guide_orientation($i) == ORIENTATION_VERTICAL){
|
||||
$keyval = sprintf("%4d", $img->get_guide_position($i));
|
||||
if ($img->get_guide_orientation($i) == &Gimp::VERTICAL_GUIDE){
|
||||
$keyval = sprintf("%4d", $img->get_guide_position($i));
|
||||
$vkeys{$keyval} = $i;
|
||||
}
|
||||
}
|
||||
foreach $key(sort (keys %vkeys)) {
|
||||
# print "Unshifting ", $key, "\n";
|
||||
# print "Unshifting ", $key, "\n";
|
||||
push @vguides, $vkeys{$key};
|
||||
}
|
||||
return @vguides;
|
||||
}
|
||||
|
||||
sub get_hguides { # get back an ordered set of horizontal guides
|
||||
#
|
||||
# Generates an ordered list of all existing horizontal guides.
|
||||
#
|
||||
|
||||
sub get_hguides {
|
||||
my ($img)=@_;
|
||||
$i=0;
|
||||
my @hguides;
|
||||
while ($i=$img->find_next_guide($i)) {
|
||||
if ($img->get_guide_orientation($i) == ORIENTATION_HORIZONTAL){
|
||||
$keyval = sprintf("%4d", $img->get_guide_position($i));
|
||||
if ($img->get_guide_orientation($i) == &Gimp::HORIZONTAL_GUIDE){
|
||||
$keyval = sprintf("%4d", $img->get_guide_position($i));
|
||||
$hkeys{$keyval} = $i;
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +61,16 @@ sub get_hguides { # get back an ordered set of horizontal guides
|
|||
return @hguides;
|
||||
}
|
||||
|
||||
sub dosel { # do the selection
|
||||
#
|
||||
# Duplicate, crop and save the image fragment.
|
||||
#
|
||||
|
||||
sub dosel {
|
||||
($img, $savepath, $imgpath, $imgbasename, $l,$r,$t,$b, $i,$j) = @_;
|
||||
$filename =~ m/^(.*)\.[^\.]*$/ ;
|
||||
$imgname = "$imgbasename-$i-$j.gif";
|
||||
$tmpimg = $img->channel_ops_duplicate;
|
||||
# print "Cropping from $l to $r, $t to $b\n";
|
||||
# print "Cropping from $l to $r, $t to $b\n";
|
||||
$tmpimg->crop($r-$l, $b-$t, $l, $t);
|
||||
$tmplay = $tmpimg->active_drawable;
|
||||
if (! $tmplay->indexed) {
|
||||
|
@ -60,36 +81,42 @@ sub dosel { # do the selection
|
|||
return "$imgpath$imgname"; # what I want printed in html
|
||||
}
|
||||
|
||||
#
|
||||
# HTML Table Generation Functions
|
||||
#
|
||||
|
||||
sub html_table_start {
|
||||
($fn,$cellpadding,$cellspacing,$border,$capatalize) = @_;
|
||||
$str = $capatalize ? "<TABLE CELLSPACING=$cellspacing CELLPADDING=$cellpadding BORDER=$border>\n" :
|
||||
"<table cellspacing=$cellspacing cellpadding=$cellpadding border=$border>\n" ;
|
||||
print $fn $str;
|
||||
$str = $capatalize ?
|
||||
"<TABLE CELLSPACING=$cellspacing CELLPADDING=$cellpadding BORDER=$border>\n" :
|
||||
"<table cellspacing=$cellspacing cellpadding=$cellpadding border=$border>\n" ;
|
||||
print $fn $str;
|
||||
}
|
||||
|
||||
sub html_table_row_start {
|
||||
($fn, $capatalize) = @_;
|
||||
$str = $capatalize ? "\t<TR>\n" : "\t<tr>\n";
|
||||
print $fn $str;
|
||||
$str = $capatalize ? "\t<TR>\n" : "\t<tr>\n";
|
||||
print $fn $str;
|
||||
}
|
||||
|
||||
sub html_table_entry {
|
||||
($fn, $imgname, $width, $height, $capatalize) = @_;
|
||||
$str = $capatalize ? "\t\t<TD><IMG SRC=\"$imgname\" WIDTH=\"$width\"HEIGHT=\"$height\"></TD>\n" :
|
||||
"\t\t<td><img src=\"$imgname\" width=\"$width\"height=\"$height\"></td>\n";
|
||||
print $fn $str;
|
||||
$str = $capatalize ?
|
||||
"\t\t<TD><IMG SRC=\"$imgname\" WIDTH=\"$width\"HEIGHT=\"$height\"></TD>\n" :
|
||||
"\t\t<td><img src=\"$imgname\" width=\"$width\"height=\"$height\"></td>\n";
|
||||
print $fn $str;
|
||||
}
|
||||
|
||||
sub html_table_row_end {
|
||||
($fn, $capatalize) = @_;
|
||||
$str = $capatalize ? "\t</TR>\n" : "\t</tr>\n";
|
||||
print $fn $str;
|
||||
$str = $capatalize ? "\t</TR>\n" : "\t</tr>\n";
|
||||
print $fn $str;
|
||||
}
|
||||
|
||||
sub html_table_end {
|
||||
($fn, $capatalize) = @_;
|
||||
$str = $capatalize ? "</TABLE>\n":"</table>\n";
|
||||
print $fn $str;
|
||||
$str = $capatalize ? "</TABLE>\n":"</table>\n";
|
||||
print $fn $str;
|
||||
}
|
||||
|
||||
# <tigert> Save-path: [_____________________][browse]
|
||||
|
@ -102,22 +129,22 @@ sub html_table_end {
|
|||
# cellspacing: ___^
|
||||
|
||||
register "perlotine",
|
||||
"Guilotine implemented ala perl, with html output",
|
||||
"Add guides to an image. Then run this. It will cut along the guides, and give you the html to reassemble the resulting images.",
|
||||
"Seth Burgess",
|
||||
"Seth Burgess <sjburges\@gimp.org>",
|
||||
"1999-07-30",
|
||||
"<Image>/Image/Transforms/Perl-o-tine",
|
||||
"*",
|
||||
[
|
||||
[PF_STRING, "save_path", "The path to export the HTML to",$ENV{HOME}],
|
||||
[PF_STRING, "html_file_name", "Filename to export","perlotine.html"],
|
||||
[PF_STRING, "image_basename", "What to call the images","perlotine"],
|
||||
[PF_TOGGLE, "separate_image_dir", "Use a separate directory for images?",0],
|
||||
[PF_STRING, "relative_image_path", "The path to export the images to, relative to the Save Path", "images/"],
|
||||
[PF_TOGGLE, "capitalize_tags", "Capatalize HTML tags?", 0],
|
||||
[PF_SPINNER, "cellspacing", "Add space between the table elements", 0, [0,15,1]],
|
||||
], sub {
|
||||
"Guilotine implemented ala perl, with html output",
|
||||
"Add guides to an image. Then run this. It will cut along the guides, and give you the html to reassemble the resulting images.",
|
||||
"Seth Burgess",
|
||||
"Seth Burgess <sjburges\@gimp.org>",
|
||||
"1999-03-19",
|
||||
"<Image>/Guides/Perl-o-tine",
|
||||
"*",
|
||||
[
|
||||
[PF_STRING, "save_path", "The path to export the HTML to",$ENV{HOME}],
|
||||
[PF_STRING, "html_file_name", "Filename to export","perlotine.html"],
|
||||
[PF_STRING, "image_basename", "What to call the images","perlotine"],
|
||||
[PF_TOGGLE, "separate_image_dir", "Use a separate directory for images?",0],
|
||||
[PF_STRING, "relative_image_path", "The path to export the images to, relative to the Save Path", "images/"],
|
||||
[PF_TOGGLE, "capitalize_tags", "Capatalize HTML tags?", 0],
|
||||
[PF_SPINNER, "cellspacing", "Add space between the table elements", 0, [0,15,1]],
|
||||
], sub {
|
||||
|
||||
my($img,$layer,$savepath, $htmlname, $imgbasename, $separate, $imgpath, $capatalize, $cellspacing) =@_;
|
||||
|
||||
|
@ -127,22 +154,36 @@ register "perlotine",
|
|||
if (!(scalar(@vert) || scalar(@horz))) {
|
||||
die ("No horizontal or vertical guides found. Aborted.");
|
||||
}
|
||||
|
||||
#
|
||||
# Progress Bar
|
||||
#
|
||||
|
||||
gimp_progress_init("Perl-o-Tine");
|
||||
$progress_increment = 1/(scalar(@horz) * scalar(@vert));
|
||||
$progress = 0.0;
|
||||
|
||||
# (Debugging info for the guide functions)
|
||||
|
||||
# print @vert, " LEN = ", scalar(@vert), "\n";
|
||||
# print @horz, " LEN = ", scalar(@horz), "\n";
|
||||
# foreach $guide (@vert) {
|
||||
# print $img->get_guide_position($guide), "\n";
|
||||
# }
|
||||
# print $img->get_guide_position($guide), "\n";
|
||||
# }
|
||||
|
||||
#
|
||||
# Correctly format paths and filenames
|
||||
#
|
||||
if (!($savepath=~ m,/$,)) { # add a trailing slash if its not on there
|
||||
$savepath = $savepath . "/";
|
||||
}
|
||||
|
||||
if (!($savepath=~ m,/$,)) { # add a trailing slash if its not on there
|
||||
$savepath = $savepath . "/";
|
||||
}
|
||||
|
||||
if (!($imgpath=~ m,/$,)) { # add a trailing slash if its not on there
|
||||
$imgpath= $imgpath . "/";
|
||||
}
|
||||
if (!$separate) { $imgpath = ""; }
|
||||
if (!($imgpath=~ m,/$,)) { # add a trailing slash if its not on there
|
||||
$imgpath= $imgpath . "/";
|
||||
}
|
||||
if (!$separate) { $imgpath = ""; }
|
||||
|
||||
# open HTML file for writing
|
||||
open FILE, ">$savepath$htmlname" or die "Couldn't open $savepath$filename: $!\n";
|
||||
|
||||
$top=0;
|
||||
|
@ -156,6 +197,10 @@ register "perlotine",
|
|||
$imgname = dosel($img, $savepath, $imgpath, $imgbasename, $left, $right, $top, $bot, $i, $j);
|
||||
html_table_entry(\*FILE, $imgname, $right-$left, $bot-$top, $capatalize);
|
||||
$left = $right + $cellspacing;
|
||||
|
||||
# Increment the progress bar
|
||||
$progress += $progress_increment;
|
||||
gimp_progress_update ($progress);
|
||||
}
|
||||
html_table_row_end(\*FILE, $capatalize);
|
||||
$top = $bot + $cellspacing;
|
||||
|
|
Loading…
Reference in New Issue