Last active
December 14, 2015 10:59
-
-
Save foxiepaws/5075506 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
#set variables | |
use vars qw(%c @p $s); | |
use HTML::Template; | |
our %c=(i=>"full/",t=>"thumbs/",p=>"/home/fox/testg/",T=>"/home/fox/tmpls/"); | |
our @p; | |
our $s=HTML::Template->new(filename=>$c{T}.'single.tmpl'); | |
# move to the image directory and glob image formats | |
chdir $c{p}.$c{i};@p=<*.jpg>,<*.gif>,<*.png>,<*.jpeg>; | |
# thumbnail images if no thumbnail exists | |
foreach(@p){ | |
if(!(-f $c{p}.$c{t}.$_)){ | |
system("convert ".$c{p}.$c{i}.$_." -thumbnail 260x180 ".$c{p}.$c{t}.$_) | |
} | |
} | |
# open index file | |
open (G,">".$c{p}."index.html"); | |
# generate index file using an anonymous function. | |
print G (sub { | |
my $a=HTML::Template->new(filename=>$c{T}.'index.tmpl'); | |
my @b; | |
foreach(@p){ | |
my %d; | |
$d{LINK}="$_.html"; | |
$d{THUMB}=$c{t}.$_; | |
push @b,\%d | |
} | |
$a->param(GALLERY=>\@b); | |
return $a->output | |
})->(); | |
#close index file | |
close G; | |
# get number of pictures | |
my $a=scalar @p; | |
# make it so that if you hit next on the last picture or previous on the first, it cycles though again | |
for(my $b=0;$b<$a;$b++){ | |
my($d,$e); | |
if($b==0){ | |
$d=$p[$a-1]; | |
$e=$p[$b+1] | |
}elsif($b==$a-1){ | |
$d=$p[$b-1]; | |
$e=$p[0] | |
}else{ | |
$d=$p[$b-1]; | |
$e=$p[$b+1] | |
} | |
my $f=$p[$b]; | |
# open the image page | |
open(G,">".$c{p}.$p[$b].".html"); | |
#generate the image page using this anonymous function | |
print G (sub { | |
my($a,$b,$c)=@_; | |
$s->param(PATH=>$c{i}.$a,PREV=>"$b.html",NEXT=>"$c.html"); | |
return $s->output | |
})->($f,$d,$e); | |
# close image page | |
close G | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment