#!/usr/bin/perl -wT

#---libsetup---

# having . in @INC can cause tainting issues for use

no lib '.';

use FindBin;
BEGIN {
  ($dir)=($FindBin::Bin=~/^([\w\d\-\/\.]+)$/)
    or die "invalid current directory $FindBin::Bin";
}
use lib $dir;

#---endlibsetup---

require IO::String;

use PhotoPub::Global qw(&init &finit $error);
use PhotoPub::CGIBase qw($query &printheader);
use PhotoPub::Config;

use PhotoPub::Utils qw(&untaint &makeabsolutepath);
use PhotoPub::Images qw(&picfile);
use PhotoPub::Ages qw(&updateagefromfiles);
use PhotoPub::Handlers qw(&handlephoto);

use PhotoPub::InfoHelper qw(&printout);

use Image::Info qw(image_info);
use Image::Magick;

init();

use strict;

my $photo=$query->param('photo') 
  or &$error(type=>'userinput',message=>'Must give a photo!');
&makeabsolutepath(\$photo);

updateagefromfiles($0);

my $picfile=&picfile($photo);

printheader(type => 'text/plain');

my $printablere='^[\w\s\/\:\(\.\)\=\-\>]*$';

my $whentaken=&handlephoto('whentaken',$photo);
print "taken: $whentaken\n\n" if defined $whentaken;

my $pic = new Image::Magick;
if(my $res = $pic->Read('JPG:'.$picfile)) { 
  &$error(type => 'picture',
	  message => $res);
}

print "quality: ".$pic->Get('quality')."\n";

my $info=image_info($picfile);
&printout('',$info,$printablere);

&finit();
