#!/usr/bin/perl -w

#---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---

use PhotoPub::Global qw(&init &finit $error);
use PhotoPub::CLBase qw();
use PhotoPub::Config;

use PhotoPub::Options qw(&initoptions &setoptions);
use PhotoPub::Cache qw(&imagefile &imagesize);

use Getopt::Long;
use Image::Magick;

&init();

&GetOptions(\%options, "rotate=s", "crop=s", "shrink=s", 
	    "thumb=s") || die 'invalid parameters';

my $image_options=&initoptions();

&setoptions($image_options,\%options);

scalar @ARGV >= 1 || die 'invalid parameters';

my $imagepath=$ARGV[0];

my ($guessedwidth,$guessedheight)=&imagesize($imagepath,$image_options);

print 'Guessed: '.$guessedwidth.'x'.$guessedheight."\n";

my $imagefile=&imagefile($imagepath,$image_options);

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

my ($width,$height)=$image->Get('width','height');

print 'Got    : '.$width.'x'.$height."\n";

&finit();
