package Template::Plugin::Image::Info;
use base qw( Template::Plugin );
use Template::Plugin;
use Image::Info qw( image_info );
use File::Basename;

sub new {
    my $class = shift;
    my $context = shift;

    # dereference the arguments if necessary
    my @files = map { ref eq 'ARRAY' ? @{$_} : $_ } @_;

    my @info = map {
	# get the full path if we are passed a TT File object
	$_ = $_->{path} if ref eq 'Template::Plugin::File';

	# store the image info in a hashref
	my $i = image_info($_);

	# add relative and absolute paths
	$i->{path} = $_;
	($base,$path,$ext) = fileparse($_,'\w+');
	$i->{name} = $base.$ext;
	$i
    } @files;

    # fold array and return to template
    return  $#info < 1 ? shift @info : \@info;
}

1;
