#!/usr/bin/perl ################################################################################ # make html files to display jpg file(s) # coder: tuan pham # developed: some time during summer 2002 when my roommate was russie # last updated: 06/25/02 (added a table for title and name) # 08/31/02 (changed the textcolor of title to FAFAFA) # 12/31/02 (added -t for title and changed script name to mkphoto.pl) # 01/04/03 (added -c=yyyy) # 01/05/03 (fixed parsing the title w/ html tags) # 04/06/03 fixed invalid html tags # 06/13/06 add website url and parents link # 03/28/08 add Previous and Next link # usage: mkphoto.pl -t="photo title" a.jpg (make html for one file) # the output will be *.html # requirements: # os: anything that dont crash on you # perl: any version that can interpret this code # others: ImageMagick package that has `identify` and A LOT of photos in jpg or png format #----------------------------------------oOo---------------------------------------- # global vars $Title=""; $Name="Tuan Pham"; $CurrentFile=""; $Site="http://photo.neofob.org"; $Header=""; $Body=""; $Tail=""; $Width; $Year=`date | awk '{print \$6}'`; # get the current year chomp $Year;; #----------------------------------------oOo---------------------------------------- #print "@ARGV[0]\t@ARGV[1]\n"; $PrevFile="./index.html"; $NextFile="./index.html"; main(); #----------------------------------------oOo---------------------------------------- sub main { makeHtml(); # generate the html header and tail my $temp,$bYear=""; my $t=0,$i=0; my @A_PARA; my @array; while ($i<2) # parse two parameters { @A_PARA=split("=",@ARGV[0]); # parse the first argument for (@A_PARA[0]) { /-t/ and do { $Title=@ARGV[0]; $Title=~s/-t=//; $t=1; shift(@ARGV); }; /-c/ and do { $bYear=@A_PARA[1]; shift(@ARGV); }; } # for loop $i++; } # while loop # while ( $AFile=shift(@ARGV) ) if ( $AFile=shift(@ARGV) ) { if ( @ARGV[0] ) { $PrevFile=@ARGV[0]; } if ( @ARGV[1] ) { $NextFile=@ARGV[1]; } if ( open (TEMP,$AFile) ) # check whether this file exist { $FileName=$AFile; # get filename of this one $CurrentFile=$AFile; $FileName=~s/\.([^\.]+)/\.html/; # replace the extension w/ html $temp=`identify $CurrentFile`; @array=split(/\s/,$temp); # parse the output $temp=@array[2]; # grab resolution in WxH @array=split(/x/,$temp); # parse the number $Width=@array[0]; # grab the width, $Width is global variable @t=split(/\./,$FileName); if ($t==0) { $Title=@t[0]; } open(OUTFILE,"> $FileName"); # create html file makeHtml(); # generate the html header and tail makeBody(); print OUTFILE "$Header $Body $Tail\n"; close(OUTFILE); close(TEMP); } } } #-------------------------oOo-------------------------- # generate the actual code that display the jpg file # information is from $CurrentFile sub makeBody { $Body="\t\t\n". "\t\t \n". "\t\t \n". "\t\t \n\n". "\t\t\n". "\t\t\n". "\t\t
\n". "\t\t\t\n". "\t\t\t"$Title"\n". "\t\t\t\n". "\t\t\n". "\t\t\t\n"; if ("" eq $bYear) { $Body.="\t\t\t ©$Year $Name\n"; } else { $Body.="\t\t\t ©$bYear-$Year $Name\n"; } $Body.="\t\t\t\n". "\t\t
\n\n". "\t\t\n". "\t\t\n". "\t\t". " ". " ". " \n". "\t\t\n". "\t\t
PreviousHomeUpNext
\n"; } #-------------------------oOo-------------------------- # adding the html header sub makeHtml { $DATE=localtime(); $Header="\n". "\n". "\n". "\n". "$Title"."\n\n". ""."\n\n". ""."\n\n". "\n". "

\n". "". "\n
". "\n\n"; $Tail= "
"."\n". ""."\n". ""; } #-------------------------oOo--------------------------