## @(#) $Header: $
## Allen Brown
## date="20010517 19:28:49"
## PictureInTable generates HTML to include a thumbnail picture
## into a table entry.
## The thumbnail is the handle to a URL pointer to the full
## size picture.
## TextInTable is a companion function to include text into a
## table entry. TextInTable is pretty trivial, but is included
## so that text and picture table entries are handled equivalently.
## If a source picture exists for the picture to be included, the
## included picture will be created if one of two conditions is
## met: the source is newer, or the included doesn't exist.
## The source picture must exist in a subdirectory of "PicSrcLink"
## relative to where the included picture exists. It is intended
## that "PicSrcLink" be a symlink to the actual source directory.
## This way the sources can be very large. And a tar of the
## web site will get only what the viewer wants. In place of the
## the large directory of source pictures, there will just be the
## symlinks.
## The thumbnail will be created if the included picture is newer or
## if the thumbnail doesn't exist.
## The picture type of the included picture and the thumbnail is
## defined by the macro "PictureInTableIncludeType". The picture
## typeof the source picture is defined by the macro
## "PictureInTableSourceType". The thumbnail size is defined by
## the macro "PictureInTableThmbSize". Default values are stored
## in /usr/local/lib/webc/include/PictureInTable.wh
###################################################################
## After the following declarations:
###################################################################
## #localcode PictureInTable.lc
## #callable PictureInTable
###################################################################
## Example: the source code listed here:
###################################################################
##
##
## PictureInTable("AB_MY_Rex98.jpg","Mark Yule riding Rex")
## TextInTable("Mark visited me from New Mexico in April of 1998. This was the first time he actually saw Rex.")
##
##
###################################################################
## Generates the following HTML:
###################################################################
##
##
##
##
##
##
## |
##
##
## Mark visited me from New Mexico in April of 1998. This was the first time he actually saw Rex.
##
## |
##
##
###################################################################
## Requirements:
###################################################################
## The parameter list to PictureInTable MUST be on ONE line.
## Parameters MUST be separated by commas.
## Quotes are recommended around all parameters.
###################################################################
## Input Parameters:
###################################################################
## Two variables are passed to this program to accomplish this:
## $picturename In the example above this is "AB_MY_Rex98".
## $alternate This is "Allen Brown and Mark Yule riding Rex".
###################################################################
## To Do List:
###################################################################
## Several features will be desirable in this program (some day).
## Reformat $commentary.
## Allow $alternate to be optional.
## Show picture size in the HTML document.
###################################################################
## Derived Variables
###################################################################
## source = $picturename ~= s%/%/PicSrcLink/% ~= s%$%.tif%
## included image = $picturename . ".jpg"
## thumbnail = $picturename . "_tn.jpg"
sub PictureInTable # ()
{
my($picturename, $alternate);
($picturename, $alternate) = eval $_[0];
if( ! defined($alternate) )
{
$alternate = $picturename . "." . "jpg";
}
$PictureInTableSourceType=$Symbols{'PictureInTableSourceType'};
$PictureInTableIncludeType=$Symbols{'PictureInTableIncludeType'};
$PictureInTableIncludeSize=$Symbols{'PictureInTableIncludeSize'};
$PictureInTableIncludeQual=$Symbols{'PictureInTableIncludeQual'};
$PictureInTableThmnailSize=$Symbols{'PictureInTableThmnailSize'};
$PictureInTableThmnailQual=$Symbols{'PictureInTableThmnailQual'};
my($picturetiff, $picturetif, $picturefull1, $picturefull2, $picturethmb,
$mtimetif, $mtimefull, $mtimethmb, $dummy,
$callline, $progname, $update, $returnvalue);
my($PictureInTableIncludeTypeL)="uninitialized";
my($PictureInTableSourceTypeL)="uninitialized";
$progname = "PictureInTable";
$_=$PictureInTableIncludeType;
if( /jpg/ )
{
$PictureInTableIncludeTypeL="jpeg";
} elsif( /tif/ )
{
$PictureInTableIncludeTypeL="tiff";
} elsif( /gif/ )
{
$PictureInTableIncludeTypeL="gif";
}
$_=$PictureInTableSourceType;
if( /jpg/ )
{
$PictureInTableSourceTypeL="jpeg";
} elsif( /tif/ )
{
$PictureInTableSourceTypeL="tiff";
} elsif( /gif/ )
{
$PictureInTableSourceTypeL="gif";
}
$picturetif = $picturename . "." . $PictureInTableSourceType;
$picturetif =~ s%(.*)/%$1/PicSrcLink/%;
$picturetiff = $picturename . "." . $PictureInTableSourceTypeL;
$picturetiff =~ s%(.*)/%$1/PicSrcLink/%;
# print( STDERR "found ", $picturetiff, "\n" );
$picturefull1 = $picturename . "." . $PictureInTableIncludeType; # Name of full size pic.
$picturefull2 = $picturetif; # Alternate name of pic.
$picturefull2 =~ s%.[a-z]*$%%;
$picturefull2 = $picturefull2 . "." . $PictureInTableIncludeType;
$picturefull2L = $picturetif; # Alternate name of pic.
$picturefull2L =~ s%.[a-z]*$%%;
$picturefull2L = $picturefull2L . "." . $PictureInTableIncludeTypeL;
$picturefull3 = $picturetif; # Alternate name of pic.
$picturefull3 =~ s%.[a-z]*$%%;
$picturefull3 = $picturefull3 . "_big." . $PictureInTableIncludeType;
$picturethmb = $picturename . "_tn." . $PictureInTableIncludeType; # Name of thumbnail.
$callline = "#call " . $progname . " \"" . $picturename . "\", \"" . $alternate . "\"";
# Check for existence of JPEG files.
if( -f $picturetiff )
{
print( STDERR "Moving ", $picturetiff, " to ",
$picturetif, ".\n" );
$returns=`mv $picturetiff $picturetif`;
}
if( -f $picturetif )
{
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimetif, $dummy, $dummy, $dummy )
= stat($picturetif);
} else {
$mtimetif = 0;
}
if( -f $picturefull1 )
{
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimefull, $dummy, $dummy, $dummy )
= stat($picturefull1);
} else {
$mtimefull = 0;
if( $mtimetif == $mtimefull )
{
print( STDERR $progname,
": ", $Symbols{'__SOURCE__'},
" line ", $Symbols{'__LINE__'},
": file '", $picturefull1, "' not found\n" );
## ": " ,__FILE__,
}
}
if( $mtimefull < $mtimetif )
{
print( STDERR "Updating ", $picturefull1, " from ",
$picturetif, ".\n" );
$returns=`mogrify -format $PictureInTableIncludeTypeL -normalize -quality 75 $picturetif`;
$returns=`mv $picturefull2L $picturefull3`;
$returns=`mogrify -format $PictureInTableIncludeTypeL -normalize -geometry '${PictureInTableIncludeSize}>' -quality $PictureInTableIncludeQual $picturetif`;
$returns=`mv $picturefull2L $picturefull2`;
if( length($returns) >= 0 )
{
if( -f $picturefull2 )
{
$returns=`cp $picturefull2 $picturefull1`;
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimefull, $dummy, $dummy, $dummy )
= stat($picturefull1);
}
} else {
print( STDERR $progname, ": Full picture generation failed",
" with '", $returns, "'.\n" );
$mtimefull = 0;
}
}
if( -f $picturethmb )
{
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimethmb, $dummy, $dummy, $dummy )
= stat($picturethmb);
} else {
$mtimethmb = 0;
}
## print( STDERR "found\n" );
## print( STDERR "What? ", $mtimethmb, ", ", $mtimefull, "\n" );
if( $mtimethmb <= $mtimefull )
{
print( STDERR "Updating ", $picturethmb, " from ",
$picturefull1, ".\n" );
$returns=`cp $picturefull1 $picturethmb`;
$returns=`mogrify -quality $PictureInTableThmnailQual -normalize -geometry '${PictureInTableThmnailSize}>' $picturethmb`;
if( 0 < length($returns) )
{
print( STDERR $progname, ": Thumbnail generation failed",
" with '", $returns, "'.\n" );
}
}
$returnvalue = "\n" .
" \n" .
" \n" .
" \n" .
" \n" .
" \n" .
" \n" .
" | \n";
return( $returnvalue );
} # PictureInTable
##################################################################
sub PictureInline # ()
{
my($picturename, $alternate);
($picturename, $alternate) = eval $_[0];
if( ! defined($alternate) )
{
$alternate = $picturename . "." . "jpg";
}
$PictureInlineSourceType=$Symbols{'PictureInlineSourceType'};
$PictureInlineIncludeType=$Symbols{'PictureInlineIncludeType'};
$PictureInlineIncludeSize=$Symbols{'PictureInlineIncludeSize'};
$PictureInlineIncludeQual=$Symbols{'PictureInlineIncludeQual'};
$PictureInlineThmnailSize=$Symbols{'PictureInlineThmnailSize'};
$PictureInlineThmnailQual=$Symbols{'PictureInlineThmnailQual'};
my($picturetiff, $picturetif, $picturefull1, $picturefull2, $picturethmb,
$mtimetif, $mtimefull, $mtimethmb, $dummy,
$callline, $progname, $update, $returnvalue);
my($PictureInlineIncludeTypeL)="uninitialized";
my($PictureInlineSourceTypeL)="uninitialized";
$progname = "PictureInline";
$_=$PictureInlineIncludeType;
if( /jpg/ )
{
$PictureInlineIncludeTypeL="jpeg";
} elsif( /tif/ )
{
$PictureInlineIncludeTypeL="tiff";
} elsif( /gif/ )
{
$PictureInlineIncludeTypeL="gif";
}
$_=$PictureInlineSourceType;
if( /jpg/ )
{
$PictureInlineSourceTypeL="jpeg";
} elsif( /tif/ )
{
$PictureInlineSourceTypeL="tiff";
} elsif( /gif/ )
{
$PictureInlineSourceTypeL="gif";
}
$picturetif = $picturename . "." . $PictureInlineSourceType;
$picturetif =~ s%(.*)/%$1/PicSrcLink/%;
$picturetiff = $picturename . "." . $PictureInlineSourceTypeL;
$picturetiff =~ s%(.*)/%$1/PicSrcLink/%;
# print( STDERR "found ", $picturetiff, "\n" );
$picturefull1 = $picturename . "." . $PictureInlineIncludeType; # Name of full size pic.
$picturefull2 = $picturetif; # Alternate name of pic.
$picturefull2 =~ s%.[a-z]*$%%;
$picturefull2 = $picturefull2 . "." . $PictureInlineIncludeType;
$picturefull2L = $picturetif; # Alternate name of pic.
$picturefull2L =~ s%.[a-z]*$%%;
$picturefull2L = $picturefull2L . "." . $PictureInlineIncludeTypeL;
$picturefull3 = $picturetif; # Alternate name of pic.
$picturefull3 =~ s%.[a-z]*$%%;
$picturefull3 = $picturefull3 . "_big." . $PictureInlineIncludeType;
$picturethmb = $picturename . "_tn." . $PictureInlineIncludeType; # Name of thumbnail.
$callline = "#call " . $progname . " \"" . $picturename . "\", \"" . $alternate . "\"";
# Check for existence of JPEG files.
if( -f $picturetiff )
{
print( STDERR "Moving ", $picturetiff, " to ",
$picturetif, ".\n" );
$returns=`mv $picturetiff $picturetif`;
}
if( -f $picturetif )
{
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimetif, $dummy, $dummy, $dummy )
= stat($picturetif);
} else {
$mtimetif = 0;
}
if( -f $picturefull1 )
{
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimefull, $dummy, $dummy, $dummy )
= stat($picturefull1);
} else {
$mtimefull = 0;
if( $mtimetif == $mtimefull )
{
print( STDERR $progname,
": ", $Symbols{'__SOURCE__'},
" line ", $Symbols{'__LINE__'},
": file '", $picturefull1, "' not found\n" );
## ": " ,__FILE__,
}
}
if( $mtimefull < $mtimetif )
{
print( STDERR "Updating ", $picturefull1, " from ",
$picturetif, ".\n" );
$returns=`mogrify -format $PictureInlineIncludeTypeL -normalize -quality 75 $picturetif`;
$returns=`mv $picturefull2L $picturefull3`;
$returns=`mogrify -format $PictureInlineIncludeTypeL -normalize -geometry '${PictureInlineIncludeSize}>' -quality $PictureInlineIncludeQual $picturetif`;
$returns=`mv $picturefull2L $picturefull2`;
if( length($returns) >= 0 )
{
if( -f $picturefull2 )
{
$returns=`cp $picturefull2 $picturefull1`;
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimefull, $dummy, $dummy, $dummy )
= stat($picturefull1);
}
} else {
print( STDERR $progname, ": Full picture generation failed",
" with '", $returns, "'.\n" );
$mtimefull = 0;
}
}
if( -f $picturethmb )
{
( $dummy, $dummy, $dummy, $dummy, $dummy, $dummy, $dummy,
$dummy, $dummy, $mtimethmb, $dummy, $dummy, $dummy )
= stat($picturethmb);
} else {
$mtimethmb = 0;
}
## print( STDERR "found\n" );
## print( STDERR "What? ", $mtimethmb, ", ", $mtimefull, "\n" );
if( $mtimethmb <= $mtimefull )
{
print( STDERR "Updating ", $picturethmb, " from ",
$picturefull1, ".\n" );
$returns=`cp $picturefull1 $picturethmb`;
$returns=`mogrify -quality $PictureInlineThmnailQual -normalize -geometry '${PictureInlineThmnailSize}>' $picturethmb`;
if( 0 < length($returns) )
{
print( STDERR $progname, ": Thumbnail generation failed",
" with '", $returns, "'.\n" );
}
}
$returnvalue = "\n" .
" \n" .
" \n" .
" \n" .
"
\n" .
" \n";
return( $returnvalue );
} # PictureInline
##################################################################
sub TextInTable # ()
{
my($paragraph);
($paragraph) = eval $_[0];
my($callline, $progname, $returnvalue);
$progname = "TextInTable";
$callline = "#call " . $progname . " \"" . $paragraph . "\"";
$returnvalue = "\n" .
" \n" .
" \n" .
" \n" .
" " . $paragraph . "\n" .
" | \n";
return( $returnvalue );
} # TextInTable
##################################################################
sub LinkInTable # ()
{
my($link,$paragraph);
($link,$paragraph) = eval $_[0];
my($callline, $progname, $returnvalue);
$progname = "LinkInTable";
$callline = "#call " . $progname . " \"" . $link . " \"" . $paragraph . "\"";
$returnvalue = "\n" .
" \n" .
" \n" .
" \n" .
" " . $paragraph . "\n" .
## " " . $paragraph . "\n" .
" | \n";
return( $returnvalue );
} # LinkInTable
##################################################################
sub LinkInline # ()
{
my($link,$paragraph);
($link,$paragraph) = eval $_[0];
my($callline, $progname, $returnvalue);
$progname = "LinkInline";
$callline = "#call " . $progname . " \"" . $link . " \"" . $paragraph . "\"";
$returnvalue = "\n" .
" \n" .
" \n" .
" " . $paragraph . "\n";
return( $returnvalue );
} # LinkInline
##################################################################
sub AnchorInline # ()
{
my($anchor,$paragraph);
($anchor,$paragraph) = eval $_[0];
my($callline, $progname, $returnvalue);
$progname = "AnchorInline";
$callline = "#call " . $progname . " \"" . $anchor . " \"" . $paragraph . "\"";
$returnvalue = "\n" .
" \n" .
" \n" .
" " . $paragraph . "\n";
return( $returnvalue );
} # AnchorInline
##################################################################
## End this file:
return(1);
##################################################################