PoshCode Archive  Artifact [d9027cdc6b]

Artifact d9027cdc6bb6427901faffb6f4695c87b937167cff776e0adfd8a5b7563731db:

  • File Exif-query-script.ps1 — part of check-in [ac8e16f453] at 2018-06-10 13:38:38 on branch trunk — ‘Get-exif’ doesn’t seem to exist. There are various solutions suggested for this, but I could not find a way to get FNumber and Focal Length in 35mm. So I have parsed out ‘exif’ output in this script. (user: unknown size: 1825)

# encoding: ascii
# api: powershell
# title: Exif query script
# description: ‘Get-exif’ doesn’t seem to exist. There are various solutions suggested for this, but I could not find a way to get FNumber and Focal Length in 35mm.  So I have parsed out ‘exif’ output in this script.
# version: 0.1
# type: script
# license: CC0
# x-poshcode-id: 425
# x-archived: 2011-01-20T22:31:29
#
#
## 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 utility) 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. 


$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}
else {}

"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