Wednesday, June 11, 2008

Selected 'Exif' statistics script is below. There are a number of ways I can improve it: Stream output, skip csv file creation (as an interim step) read list with arrays and parameters, using regex expressions to best effect. Still, quite a few lessons learned with this and the output can help check for errors. The issue is that 'exif' (Cygwin, GNU output) will sometimes skip fields. I am not checking for that or other error conditions in general but the 'Counts' need to sync up at least. That being said, 'measure-object' cmdlet gives me some easy 'meta-file' (exif) stats about my JPGs. Output looks as below. I am still not solving the problem that I do not know how to obtain select "meta-file" information from Powershell.

Count : 214
Average :
Sum :
Maximum :
Minimum :
Property : Exif_Tag

Count : 214
Average : 7.07102803738318
Sum :
Maximum : 13
Minimum : 3.5
Property : FNumber

Count : 214
Average : 58.0140186915888
Sum :
Maximum : 82
Minimum : 27
Property : Focal_Length

## Get-exif-stats.ps1
$exif_index = gci *.jpg | %{exif ($_.Name)}
$c = $exif_index | Select-String -pattern "EXIF tag" , FNumber , "Focal Length In 35mm"
$c1 = ("$c").Split( ) | Select-String -pattern JPG , f/ , mm
$c2 = (("$c1").Replace( "'" , "")).Split()
$c3 = (("$c2").Replace( " |f/" , ",")).Split()
$c4 = (("$c3").Replace( " 35mm|" , ",")).Split()

if ((gci PhotoData.csv).Exists -eq "True") {mv PhotoData.csv PhotoData.csv.old -force}

"Exif_Tag,FNumber,Focal_Length" | out-file PhotoData.csv
$c4 | out-file -append PhotoData.csv
$PhotoData = import-csv -path PhotoData.csv

$FileName = ( $PhotoData | Measure-Object -Property Exif_Tag )
$FNumber = ( $PhotoData | Measure-Object -Property FNumber -average -maximum -minimum )
$Focal_Length = ( $PhotoData | Measure-Object -Property Focal_Length -average -maximum -minimum )

echo $FileName
echo $FNumber
echo $Focal_Length

No comments: