added new perl scripts

This commit is contained in:
Sven Neumann 2001-07-23 10:21:56 +00:00
parent f1199d33b7
commit 5af0fa4655
4 changed files with 482 additions and 0 deletions

View File

@ -1,4 +1,5 @@
Revision history for Gimp-Perl extension.
- added example scripts triangu gallery iland
- fixed typo in examples/xachvision
- added examples/circular_text by Mike Gherlone.

242
plug-ins/perl/examples/gallery Executable file
View File

@ -0,0 +1,242 @@
#!/usr/bin/perl
# gallery.pl
#
# Copyright (c) Fabian Frederick 2001
#
# 17/07/2001 (Fab)
# V2.0
# -Adding Html instance per picture + Header
# -Adding URL
#
# 07/07/2001 (Darkin)
# -Item was unreachable from menu because of RGB requesite -> undef.
#
# 17/6/2001 (Fab)
# V1.3
# -Adding global progression bar
# -Preserving Gimp cache (progressive image_delete)
# -Adding trailing / to path
# -Plugin crashed when no label was given
# 25/5/2001 (Fab)
# V1.2 -Bug in rotation parameter : OK
# -Adding color for label(Parasite editor helped here :) ).
# -Register as gallery_maker
# -Adding corner selection for copyright using layer_translate
# -Recovering colors for HTML (Thanks Marc).
#
# 18/19/5/2001 (Fab)
# V1.01 -Moving plug-in to Toolbox/Render menu
# -Added some error-handling
# -Automatically put html file in gallery path
# -Added some features to HTML generated
# -Simplified I/O
# -Status supply
# -Source is not overwritten anymore .... c$name applied.
# -Working in sub-path (using gallery title)
# -HTML file not deployed in /tmp (directly in dpath)
# 10-13/5/2001 (Fab)
# V1.0 First workable version.
#
use Gimp qw(:auto __ N_);
use Gimp::Fu;
use Gimp::Util;
#Gimp::set_trace(TRACE_ALL);
sub printHeader {
my ($rf,$gf,$bf,$r,$g,$b, $htmlFile,$gallerytitle)=@_;
printf $htmlFile "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">";
printf $htmlFile "<body bgcolor='#%x%x%x'>\n",$r,$g,$b;
printf $htmlFile "<center><font face=\"verdana,arial\" size=\"5\" color=\"#%x%x%x\">",$rf,$gf,$bf;
printf $htmlFile "$gallerytitle\n";
printf $htmlFile "<table><tr>\n";
}
sub printFooter {
my ($rf,$gf,$bf,$URL, $htmlFile)=@_;
printf $htmlFile "<br><br><hr size=\"1\" color=\"white\"><a href=\"$URL\">Back to previous page</a>\n";
printf $htmlFile "</body>\n</html>";
}
sub galleryMaker {
my ($path, $label, $labelcolor, $labelpos, $font, $bright, $contrast, $rotate, $scalefix, $fixed, $gallerytitle, $color, $foregroundcolor, $galleryfile,$columns,$parentURL) = @_;
$oldforeground=gimp_palette_get_foreground();
$path=$path.'/';
if ($path eq ""){
Gimp->message(__"All fields were not completed, sorry.");
exit main;
}
if ($fixed == 0){
Gimp->message(__"Scale factor has not to be 0");
exit main;
}
$countTotal=`ls $path*.jpg | wc -l`+`ls $path*.JPG | wc -l`;
$gallerytitle=~s/ /_/g;
opendir(cpath, $path) or die ("Unable to open destination path");
$sysval=system("mkdir $path$gallerytitle");
if ($sysval != 0){
Gimp->message(__"Make sure you've got write access to selected path ...\nMaybe the target path already exist in which case you can simply change the Gallery title and launch again");
exit main;
}
my $dpath="$path$gallerytitle/";
open (htmlFile, "> $dpath$galleryfile.html") or die ("Unable to process HTML File.");
my ($rf,$gf, $bf)=@$foregroundcolor;
my ($r,$g,$b)=@$color;
printHeader($rf,$gf,$bf,$r,$g,$b,htmlFile,$gallerytitle);
print htmlFile "<table><tr>\n";
my $totalentries=0;
my $entries=1;
my $twidthEval=0;
my $txtwidth=0;
my $txtheight=0;
my $ycorrection=0;
my $xcorrection=0;
Gimp->progress_init("Releasing the gallery");
while (defined($cfile=readdir(cpath))) {
if (( $cfile =~ /.jpg/ ) || ($cfile =~ /.JPG/)) {
my $img=gimp_file_load(RUN_NONINTERACTIVE,"$path$cfile", "$path$cfile");
my $clayer=gimp_image_get_active_layer($img);
if ($rotate != 0){
#plug_in_rotate manages both global 90-180-270 - reshape $img
plug_in_rotate(RUN_NONINTERACTIVE,$img,-1,$rotate,1);
}
my $width=gimp_image_width($img);
my $height=gimp_image_height($img);
gimp_brightness_contrast($clayer, $bright, $contrast);
if ( $label ne "" ){
my $newlayer=gimp_layer_new($img, 200, 100, RGB_IMAGE, "newlayer", 100, NORMAL_MODE);
gimp_palette_set_foreground($labelcolor);
my $txtlayer=gimp_text_fontname($img, -1, 1, 1, $label, 0, 0, 16, 0, $font);
if ($twidthEval == 0) {
$txtwidth=gimp_drawable_width($txtlayer);
$txtheight=gimp_drawable_height($txtlayer);
$twidthEval=1;
}
$ycorrection=$height-$txtheight if (($labelpos == 2) || ($labelpos == 3));
$xcorrection=$width-$txtwidth if (($labelpos == 1) || ($labelpos == 3));
gimp_layer_translate($txtlayer, $xcorrection, $ycorrection);
gimp_image_merge_visible_layers($img,0);
}
my $cvname="$dpath$cfile";
#$cvname=~s/ /c/g;
($img->get_layers)[0]->file_jpeg_save("$cvname", "$cvname",0.7,0,1,0,"",0,1,0,0);
#Processing Thumbnail
my $tbheight=1;
my $tbwidth=1;
if ($scalefix == 1){
my $scalefactor=$width/$fixed;
$tbheight=$height/$scalefactor;
$tbwidth=$fixed;
}else{
if ($scalefix == 2) {
my $scalefactor=$height/$fixed;
my $newwidth=$width/$scalefactor;
$tbwidth=$newwidth;
$tbheight=$fixed;
}else {
# scalefix 0 => both scaled by factor (value_factor)
$tbwidth=$width/$fixed;
$tbheight=$height/$fixed;
}
}
my $tbfname="$dpath $cfile";
$tbfname=~s/ /m/g;
system("cp $cvname $tbfname");
gimp_image_delete($img);
my $img=gimp_file_load(RUN_NONINTERACTIVE,"$tbfname", "$tbfname");
my $clayer=gimp_image_get_active_layer($img);
gimp_image_scale($img, $tbwidth, $tbheight);
#Processing detail HTML
my $htmlDetail=$cfile;
$htmlDetail=~s/.jpg/.html/g;
$htmlDetail=~s/.JPG/.html/g;
open (fhtmlDetail, "> $dpath$htmlDetail") or die ("Unable to process HTML File.");
printHeader($rf,$gf,$bf,$r,$g,$b,fhtmlDetail,$gallerytitle);
print fhtmlDetail "<img src=\"$cfile\"></img>";
printFooter($rf,$gf,$bf,"$galleryfile.html", fhtmlDetail);
close fhtmlDetail;
file_jpeg_save(RUN_NONINTERACTIVE,$img, ($img->get_layers)[0],"$tbfname", "$tbfname",0.7,0,1,0,"",0,1,0,0);
print htmlFile " <td><a href='$htmlDetail'><img src='m$cfile' border='0'></a></td>\n";
if ($entries >= $columns){
print htmlFile "</tr><tr>";
$entries=1;
}else{
$entries=$entries+1;
}
$totalentries=$totalentries+1;
Gimp->progress_update ($totalentries/$countTotal);
gimp_image_delete($img);
}
}
Gimp->progress_update(1);
print htmlFile "</table>\n";
printFooter($rf,$gf,$bf,$parentURL, htmlFile);
close htmlFile;
Gimp->message(__"Your gallery ($galleryfile) has been generated through Gallery plug-in with $totalentries entries");
gimp_palette_set_foreground($oldforeground);
# return();
}
$help=<<EOF.$help;
This script will hopefully help you creating an html gallery of a path full of JPG pictures ... This one creates thumbnails - Copyright notice on picture and some other cool tips.
EOF
register("gallerymaker",
"Generate your gallery in HTML format + some picture improvements",
$help,
"Fabian Frederick <Fabian.Frederick\@gmx.fr>",
"(c) 2001 Fabian Frederick",
"20010601",
N_"<Toolbox>/Xtns/Render/Gallery Maker",
undef,
[
[PF_FILE, "path", "Destination path .... "],
[PF_STRING, "label", "Text to add at the top of each picture"],
[PF_COLOR, "label_color", "Color of the label to be displayed on each picture", [255,255,255]],
[PF_RADIO, "label_position", "Position of your text label...", 0, [ UpLeft => 0, UpRight => 1, DownLeft => 2, DownRight => 3 ]],
[PF_FONT, "displayfont", "Select font", undef ],
[PF_SLIDER, "brightness", "Brightness correction", 0, [ -127, 127]],
[PF_SLIDER, "contrast", "Contrast correction", 0, [-127,127]],
[PF_RADIO, "rotate", "Rotation angle", 0, [ None => 0, Rotate90CCW => 3, Rotate90 => 1]],
[PF_RADIO, "scalefix", "Scale fixing for thumbnails", 1 ,[ both_by_factor => 0, X => 1, Y => 2 ]],
[PF_INT32, "value_factor", "value or factor", 150],
[PF_STRING, "gallery_title", "Gallery's Title" ],
[PF_COLOR, "background_color","Gallery background color", [100,100,100]],
[PF_COLOR, "foreground_color","Gallery background color", [255,255,255]],
[PF_STRING, "gallery_file", "HTML file generated" ],
[PF_INT32, "columns", "Gallery columns number", 2],
[PF_STRING, "parent_file", "Gallery's parent URL" ]
],
\&galleryMaker);
exit main;
__END__
=head1 NAME
Gallery Maker
=head1 SYNOPSIS
Gallery Maker
=head1 DESCRIPTION
Gallery Maker is a Gimp plugin.It generates an HTML file from all pictures it finds in a designed path.A thumbnail is generated from each picture with a desired global scale or X or Y fixed...This tool will hopefully help batch conversions from photo albums for instance as you can add copyright notice on source picture but also adjust brightness/contrast or give polar rotations ....
Convention used here is the following : All pictures converted is c<name> ....Relative thumbnail is m<name>
Note : This plugin only processes JPG pictures.
=head1 AUTHOR
Written by Fabian Frederick <fabian.frederick@gmx.fr>, (c) 2001

136
plug-ins/perl/examples/iland Executable file
View File

@ -0,0 +1,136 @@
#!/usr/bin/perl
# iland.pl
#
# Copyright (c) Fabian Frederick 2001
#
# 02/06/2001
# V1.0
# -The stuff works but it's still slow.
# Problem resides in the brutal m/slice.
# I hope to find out some artifact to use PDL more efficiently for this "non-matrix" algorithm.
#
#
use Gimp::Feature 'pdl';
use Gimp qw(:auto __ N_);
use Gimp::Fu;
use PDL::LiteF;
sub landscape {
my ($image, $drawable, $floor,$component, $delta,$elevation, $camerapos) = @_;
#gimp_tile_cache_size(20000);
gimp_selection_clear($image);
plug_in_rotate(RUN_NONINTERACTIVE, $image, -1, $camerapos, 1) if ($camerapos != 0);
$width=gimp_image_width($image);
$height=gimp_image_height($image);
my $gdrawable=$drawable->get();
#Pixel region of selection
my $src= new PixelRgn ($drawable, 0,0,$width, $height, 0, 0);
my $newimage=gimp_image_new($src->w, $src->h, 0);
$layer=gimp_layer_new($newimage,$src->w, $src->h, RGB_IMAGE, "L1", 100, NORMAL_MODE);
gimp_image_add_layer($layer, -1);
$newdrawable=gimp_image_active_drawable($newimage);
my $dest = new PixelRgn ($newdrawable, 0,0,$width, $height,1,1);
Gimp->progress_init("Rendering...");
my $relord=$src->w/255;
gimp_drawable_fill($newdrawable, 0);
$delta=1 if ($delta<1);
for (my $y=0; $y<$src->h; $y++){
$row=$src->get_row(0, $y, $src->w);
my $drow=$row&0;
$red=$row->slice($component);
$dred=$drow->slice(0);
$dgreen=$drow->slice(1);
$dblue=$drow->slice(2);
for(my $x=0;$x<$src->w;$x++){
$r=at($red,0,$x);
if ($r>$floor){
my $remain=$r;
my $currentx=$width-$r*$relord+($x/$elevation);
#Apply elevation following the x offset in original picture
while ($remain>0 && $currentx<$src->w){
if($remain>150){
set ($dblue,0,$currentx,$remain);
set ($dred,0,$currentx,0);
set ($dgreen,0,$currentx,$remain);
}
if($remain<150 && $remain>50){
set ($dgreen,0,$currentx,$remain+55);
set ($dred,0,$currentx,0);
set ($dblue,0,$currentx,0);
}
if($remain<50){
set ($dred,0,$currentx,0);
set ($dgreen,0,$currentx,0);
set ($dblue,0,$currentx,$remain+200);
}
$remain-=$delta;
$currentx++;
}
}
}
$dest->set_row($drow, 0,$y);
Gimp->progress_update($y/$src->h);
}
Gimp->progress_update(1);
$newdrawable->merge_shadow(1);
$newdrawable->update(0,0,$width, $height);
plug_in_rotate(RUN_NONINTERACTIVE, $newimage,-1,1,1);
$newdrawable->merge_shadow(1);
$newdrawable->update(0,0,$width, $height);
Gimp->display_new($newimage);
#Original pic => original state
if($camerapos==3){
$camerapos=1;
}else{
if ($camerapos==1){
$camerapos=3;
}
}
plug_in_rotate(RUN_NONINTERACTIVE, $image, -1, $camerapos, 1) if ($camerapos != 0);
}
register "intensitylandscape",
"Generate an intensity based landscape",
"Generate an alpha landscape based on intensity",
"Fabian Frederick",
"(c) 2001 Fabian Frederick",
"20010601",
N_"<Image>/Filters/Render/Intensity Landscape",
"*",
[
[PF_SLIDER, "floor", "Floor", 100, [0, 255]],
[PF_RADIO, "active_component", "Active Component", 0, [ Red => 0, Green => 1, Blue => 2]],
[PF_SLIDER, "delta", "delta color", 6, [0, 100]],
[PF_FLOAT, "elevation", "elevation argument should be 2 or 3", 2],
[PF_RADIO, "camera", "camera position", 0, [ Right => 0, Bottom => 3, Left => 2, Top => 1]]
],
\&landscape;
exit main;
__END__
=head1 NAME
Intensity Landscape
=head1 SYNOPSIS
Intensity Landscape
=head1 DESCRIPTION
Intensity Landscape is a Gimp plugin generating a landscape from original picture.The result is an interpolated view as if you were looking from one side
of the original picture (which is an taken as an apical view).
=head1 AUTHOR
Written by Fabian Frederick <fabian.frederick@gmx.fr>, (c) 2001

103
plug-ins/perl/examples/triangu Executable file
View File

@ -0,0 +1,103 @@
#!/usr/bin/perl
# triangu.pl
#
# Copyright (c) Fabian Frederick 2001
#
# 20/06 : Polygonal linking.Rendering is better
# Using I(y)
#
# 19/06/2001 : Passing gamma reference to alpha in linear scan
# First workable version
#
use Gimp::Feature 'pdl';
use Gimp qw(:auto __ N_);
use Gimp::Fu;
use PDL::LiteF;
use PDL::Slices;
use POSIX;
sub triangle {
my ($image, $drawable, $bckcolor, $xscale, $yscale, $thickness, $ground, $elevation) = @_;
$oldforeground=gimp_palette_get_foreground();
$oldbackground=gimp_palette_get_background();
gimp_palette_set_background($bckcolor);
Gimp->progress_init("Rendering...");
gimp_selection_clear($image);
$width=gimp_image_width($image);$height=gimp_image_height($image);
my $src=new PixelRgn($drawable,0,0,$width,$height, 0, 0);
for ($y=0;$y<$src->h;$y+=$yscale){
$row=$src->get_row(0,$y,$src->w);
for (my $x=0;$x<$src->w;$x+=$xscale){push @acq,[$x,($src->h-$row->slice(1)->at(0,$x)-$ground)/2];}
}
Gimp->progress_update(0.8);
my $newimage=gimp_image_new($src->w, $src->h, 0);
gimp_layer_new($newimage,$src->w, $src->h, RGB_IMAGE, "L1", 100, NORMAL_MODE)->gimp_image_add_layer(-1);
$newdrawable=gimp_image_active_drawable($newimage);
gimp_drawable_fill($newdrawable, 1);
my $thickness=sprintf("0%d", $thickness);
#gimp_brushes_set_brush("Circle (01)");
gimp_brushes_set_brush("Circle ($thickness)");
my $indline=1;my $exc=0;
for(my $ind=0,my $perline=floor($src->w/$xscale)+1;$ind<($src->h/$yscale*$src->w/$xscale)-10;){
if ($indline<($width/$xscale)){
$elvlevel=($ind/($src->w/$xscale))*$elevation;
gimp_palette_set_foreground([$acq[$ind][1],$acq[$ind][1],$acq[$ind][1]]);
gimp_pencil($newdrawable, 4, [$acq[$ind+$perline][0],$acq[$ind+$perline][1]+$elvlevel,$acq[$exc][0],$acq[$exc][1]+$elvlevel]);
gimp_pencil($newdrawable, 4, [$acq[$ind][0],$acq[$ind][1]+$elvlevel,$acq[$ind+1][0],$acq[$ind+1][1]+$elvlevel]);
gimp_pencil($newdrawable, 4, [$acq[$ind][0], $acq[$ind][1]+$elvlevel,$acq[$ind+$perline][0], $acq[$ind+$perline][1]+$elvlevel]);
gimp_pencil($newdrawable, 4, [$acq[$ind+$perline][0],$acq[$ind+$perline][1]+$elvlevel,$acq[$ind+1][0],$acq[$ind+1][1]+$elvlevel]);
$exc=$ind+$perline;
$indline=$indline+1;
}else{
$indline=1;
}
Gimp->progress_update($ind/($src->h/$yscale*$src->w/$xscale));
$ind=$ind+1;
}
$newdrawable->merge_shadow(1);
$newdrawable->update(0,0,$width, $height);
Gimp->display_new($newimage);
Gimp->progress_update(1);
gimp_palette_set_foreground($oldforeground);
gimp_palette_set_foreground($oldbackground);
}
register "triangulandscape",
"Generate a triangulation landscape",
"Generate a triangulation landscape",
"Fabian Frederick",
"(c) 2001 Fabian Frederick",
"20010701",
N_"<Image>/Filters/Render/Triangulation Landscape",
"RGB",
[
[PF_COLOR, "background_color","background color", [100,100,100]],
[PF_SLIDER, "xscan", "Stat each X coord.", 20, [1, 100]],
[PF_SLIDER, "yscan", "Stat each Y coord.", 20, [1, 100]],
[PF_SLIDER, "line_thickness", "Line thickness", 1, [1, 5]],
[PF_SLIDER, "ground", "Pixels from bottom", 50, [1, 100]],
[PF_SLIDER, "elevation", "elevation factor in pixels", 10, [1, 100]],
],
\&triangle;
exit main;
__END__
=head1 NAME
Triangulation Landscape
=head1 SYNOPSIS
Triangulation Landscape
=head1 DESCRIPTION
Triangulation Landscape is a Gimp plugin.
=head1 AUTHOR
Written by Fabian Frederick <fabian.frederick@gmx.fr>, (c) 2001