#!/perl -w
# NAME: 
# AIM:
use strict;
use warnings;
require 'logfile.pl' or die "Unable to load logfile.pl ...\n";
# log file stuff
my ($LF);
my $outfile = 'temp.'.$0.'.txt';
if ($0 =~ /\w{1}:\\.*/) {
	my @tmpsp = split(/\\/,$0);
	$outfile = 'temp.'.($tmpsp[-1]).'.txt';
}
open_log($outfile);
prt( "$0 ... Hello, World ...\n" );
my $f = 'C:\Documents and Settings\Geoff McLane\My Documents\Hommage\downloads\index_files\buttons.gif';
#my $rd = 'tempimg.txt';
#my @imargs = ('identify',"$f", '>', $rd);
#my $result = system(@imargs);
#my $ln = '';
#my $cnt = 0;
#if (open TIN, "<$rd") {
#	my @arr = <TIN>;
#	close TIN;
#	foreach $ln (@arr) {
#		chomp $ln;
#		prt( "$ln\n" );
#	}
#} else {
#	prt( "ERROR: Unable to open $rd ...\n" );
#	prt( "args passed:\n" );
#	$cnt = 0;
#	foreach $ln (@imargs) {
#		prt( "$cnt [$ln]\n" );
#		$cnt++;
#	}
#}

my $isz = get_image_size($f);
prt( "Image Size: $isz\n" );
prt( "That is ".get_image_width($isz)." by ".get_image_height($isz)." pixels.\n" );

close_log($outfile,1);
exit(0);

sub get_image_width {
	my ($is) = shift;
	my $wid = 0;
	my @arr = split(/x/,$is);
	if (scalar @arr == 2) {
		$wid = $arr[0];
	}
	return $wid;
}

sub get_image_height {
	my ($is) = shift;
	my $hgt = 0;
	my @arr = split(/x/,$is);
	if (scalar @arr == 2) {
		$hgt = $arr[1];
	}
	return $hgt;
}

sub get_image_size {
	my ($if) = shift;
	my $is = '';
	if (open (IDT, "identify \"$if\"|")) {
		my @arr2 = <IDT>;
		close IDT;
		foreach my $ln (@arr2) {
			chomp $ln;
			prt( "[$ln]\n" );
			if (substr($ln,0,length($f)) eq $f) {
				my $ln2 = substr($ln,length($f));
				$ln2 =~ s/^\s//;
				prt( "$ln2\n" );
				if ($ln2 =~ /\s(\d+x\d+)\s/) {
					$is = $1;
				}
			}
		}
	} else {
		prt( "ERROR: I can't open [$if]\n" );
	}
	return $is;
}

# eof
