#!/opt/perl5/bin/perl
############################################################
#
# $Header: E:\\RCS\\E\\Tt\\Ittc\\tools\\Photo.pm,v 1.1 2000-04-23 21:58:28+01 gael Exp $
#
# $Source: E:\\RCS\\E\\Tt\\Ittc\\tools\\Photo.pm,v $
# $Revision: 1.1 $
# $Locker:  $
#
# Module describing PHOTO class
#
############################################################

package PHOTO;

use strict;
use File::stat;

use Exporter;
use vars qw(@ISA @EXPORT $VERSION);

@ISA = qw (Exporter);

@EXPORT = qw ();

# RCS versioning
$VERSION = '$Revision: 1.1 $';
$VERSION =~ s/\$(Revision): ([0-9\.]*) \$$/$2/;

#
# ->new
#
# Attributes:
#   file: filename of the photography
#   author: author of the photography
#   description: a description to use in ALT tag
#
sub new {
    my ($self) = bless {}, shift;
    my ($file, $width, $height, $author, $description) = @_;

    $self->{'file'} = $file;
    my ($st);
    $st = stat($file);
    if ($st) {
	$self->{'size'} = $st->size;
    }
    $self->{'width'} = $width;
    $self->{'height'} = $height;
    $self->{'author'} = $author;
    $self->{'description'} = $description;
    return $self;
}

#
# Attribute access routines
#
sub file        { $_[0]->{'file'} }
sub size        { $_[0]->{'size'} }
sub width       { $_[0]->{'width'} }
sub height      { $_[0]->{'height'} }
sub author      { $_[0]->{'author'} }
sub description { $_[0]->{'description'} }

#
# ->print_html
#
# print in HTML a PHOTO object as an IMG tag and a legend
#
sub print_html {
    my ($self) = shift;
    my ($dir) = @_;
    my ($img, $legend) = ('','');

    if ($self->author) {
	$legend = 'Photo courtesy '.PLAYER->html_accents($self->author);
    }
    $img = '<IMG SRC="'.$self->file.'" ALT="Picture of '.$self->description.' ('.$self->size.' bytes)"';
    $img = $img.' WIDTH='.$self->width.' HEIGHT='.$self->height.'>';
    return ($img, $legend);
}

1;
