package PhotoPub::Images;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(&picfile &picrange &canonicalname);

use strict;

use PhotoPub::Global qw(&$error);
use PhotoPub::Handlers qw(&handlephoto &listparameterhandlephoto);
use PhotoPub::Utils qw(&parserange &getdefault);

sub picrange {
  my ($rangestr)=@_;
  my @photos=();
  my %checks=();
  &parserange($rangestr,&getdefault('path'),
	      sub {
		my ($path,$num)=@_;
		$checks{$path}=[] unless exists $checks{$path};
		push @{$checks{$path}},$num;
		return 1;
	      });
  foreach my $path (keys %checks) {
    my $validnums=&listparameterhandlephoto('existsphotos',$path,$checks{$path});
    foreach my $num (sort { $a <=> $b } @$validnums) {
      push @photos,($path.$num);
    }
  }
  return @photos;
}


sub picfile {
  my ($photo)=@_;
  return handlephoto('imagefile',$photo);
}

sub canonicalname {
  my ($photo)=@_;
  my $canonicalphoto=&handlephoto('canonicalname',$photo);
  $canonicalphoto=$photo unless defined $canonicalphoto;
  return $canonicalphoto;
}

1;
