$infile = 'data.txt';
#$infile = $batOutput;
## Output File Handles (open)
open(OUT1,"> \!".$state.$status."INFO.txt") or die "Can't open \!".$state.$status."INFO.txt: $!";
open(OUT2,"> \!".$state.$status."INFOspdsht.txt") or die "Can't open \!".$state.$status."INFO.txt $!";
open(ERRLOG,"> \!errors.log") or die "Can't open !errors.log $!";
## Print Headers To spdsht file
print OUT2 ";;;;Whitespace;;DPI ReSize;;;\n";
print OUT2 "Filename;Comp;AlphCnl;Foto;Wid;Len;Res 0;x0;;;MB\n";
## Configuration Data for masking data output
my %config = (
'LZW' => 'colors',
'Lempel-Ziv & Welch encoding' => 'colors',
'CCITT Group 4' => 'bkwhts',
'CCITT Group 4 facsimile encoding' => 'bkwhts',
'None' => 'none',
'none' => 'none',
'RGB color' => 'colors',
'min-is-white' => 'bkwhts',
'min-is-black' => 'bkwhts',
'palette color (RGB from colormap)' => 'colors',
'Resolution' => sub {
my @r = split(/, /, shift);
$r[0] =~ s/\D//g;
$r[1] =~ s/\D//g;
return @r[0,1];
},
);
my @config = keys %config;
my $file = $infile; # set this as needed.
open my $fh, '<', $file or die "can't open <$file> for reading $!";
$/ = "TYPE:\n";
while ( my $record = <$fh> ) {
chomp $record;
next if $record eq '';
$record =~ s/(TIFF Directory at offset .+)\n//;
## Future use, for incrementing errors
$errorCount = 0;
my ($fullpath, $data) = split(/\n/, $record, 2);
$fullpath =~ s/:$//;
my ($drv, $path, $file) = File::Spec->splitpath($fullpath);
## Get Compression Scheme data
$cs = $config{$1} if ($data =~ s/\s{2}Compression Scheme:\s+(.*?)\n//);
if (!defined $cs) {
print "[ERROR]: Compression Scheme for $file not found.\n";
print ERRLOG "[ERROR]: Compression Scheme for $file not found.\n";
$errorCount++;
#next;
}
## Get Photometric Interpretation data
$pi = $config{$1} if ($data =~ s/\s{2}Photometric Interpretation:\s+(.*?)\n//);
if (!defined $pi) {
print "[ERROR]: Photometric Interpretation for $file not found.\n";
print ERRLOG "[ERROR]: Photometric Interpretation for $file not found.\n";
$errorCount++;
#next;
}
## Get Bits/Sample data
$bits = $1 if ($data =~ s/\s{2}Bits\/Sample:\s+(.*?)\n//);
if (!defined $bits) {
print "[ERROR]: Bits/Sample data for $file not found.\n";
print ERRLOG "[ERROR]: Bits/Sample data for $file not found.\n";
$errorCount++;
#next;
}
## Get Samples/Pixel data
$pixels = $1 if ($data =~ s/\s{2}Samples\/Pixel:\s+(.*?)\n//);
if (!defined $pixels) {
print "[ERROR]: Samples/Pixel data for $file not found.\n";
print ERRLOG "[ERROR]: Samples/Pixel data for $file not found.\n";
$errorCount++;
#next;
}
## Get AlphaChnl Value (bits * pixels)
$alphachnl = $bits * $pixels;
if ($alphachnl == 1) {
$alphachnl = "bkwhts";
}
elsif ($alphachnl == 8) {
$alphachnl = "colors";
}
elsif ($alphachnl == 24) {
$alphachnl = "doLOGO";
}
else {
$alphachnl = "unknwn";
}
## Get Resolution data
my @r = $config{'Resolution'}->($1) if ($data =~ s/\s{2}Resolution:\s+(.*?)\n//);
## Get Width/Length data
my ($w, $l) = ($1, $2) if ($data =~ s/\s{2}Image Width: (\d+) Image Length: (\d+)\n//);
## Width
if (!defined $w) {
print "[ERROR]: Width for $file not found.\n";
print ERRLOG "[ERROR]: Width for $file not found.\n";
$errorCount++;
#next;
}
## Length
if (!defined $l) {
print "[ERROR]: Length for $file not found.\n";
print ERRLOG "[ERROR]: Length for $file not found.\n";
$errorCount++;
#next;
}
## Resolution
if (!defined $r[0] || !defined $r[1]) {
print "[ERROR]: Resolution for $file not found.\n";
print ERRLOG "[ERROR]: Resolution for $file not found.\n";
$errorCount++;
#next;
}
## Get Size of TIF(F) file(s)
my $filesize = (-s $fullpath) / (1024 * 1024);
my $size_in_mb = sprintf "%.2f", $filesize;
## Error Check
if ($errorCount > 0) {
print "[INFO]: $file was not processed, too many errors.\n";
next;
}
$data =~ s/\n$//;
## ** For Debugging - Prints To Screen **
## print $/, join(':', $file, $cs, $bits, $pi, $w, $l, @r, $size_in_mb, "\n"), $data, "\n";
print "Processing $file\n";
print OUT1 $/, join(';', $file, $cs, $bits, $pixels, $pi, $w, $l, @r, $size_in_mb, "\n"), $data, "\n";
## LA Output
if ($state eq "LA") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];;;", "$size_in_mb;;","\'$batch;;;;","start;","$file;;;;;;;;;;","$size_in_mb;","move;","$file;","$dir_root\\done;", "\n";
}
## NM Output
elsif ($state eq "NM") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];;;", "$size_in_mb;;","\'$batch;;;;","start;","$file;","$size_in_mb;","move;","$file;","$dir_root\\done;", "\n";
next;
}
## OK/UT Output
elsif ($state eq "OK" || $state eq "UT") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];;;", "$size_in_mb;;","\'$batch;;;;","start;","$file;","$size_in_mb;","move;","$file;","$dir_root\\done;","start;",$file."f;","move;",$file."f;","$dir_root\\done\\TEMPdone;", "\n";
next;
}
## TX/WY Output
elsif ($state eq "TX" || $state eq "WY") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];", "move $dir_root\\$file $dir_root\\$cs\\$file;;", "$size_in_mb;;", "\'$batch;;;","start;", "$dir_root\\$cs\\$file;", "$file;","$size_in_mb;","move;", "$dir_root\\$cs\\$file;", "$dir_root\\done;","start;", $file."f;", "move;", $file."f;", "$dir_root\\done\\TEMPdone;", "\n";
next;
}
elsif ($state eq "NONE" || $state eq "--" || $state eq "OTHER") {
print OUT2 "$file;", "$cs;", "$alphachnl;", "$pi;", "$w;", "$l;", "$r[0];$r[1];", "$size_in_mb\n";
next;
}
}
close (OUT1) or die "Can't close out1: $!";
close (OUT2) or die "Can't close out2: $!";
close (ERRLOG) or die "Can't close error log: $!";
close ($fh) or die "Can't close $fh: $!";
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE