Categories

Games: Advanced 5

In this event we have to pull some information out of the properties of some photos.  This information isn’t in the normal properties. We need to load the drawing classes to access the data.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
#http://blogs.technet.com/jamesone/archive/2007/07/13/exploring-photographic-exif-data-using-powershell-of-course.aspx
function ConvertTo-Chars {
param ($bytedata)
    $str = ""
    for ($i=0; $i -le $bytedata.Length-1;$i++){
        $str = $str + [char]$bytedata[$i]
    }
    Return $str
}
cls
[reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll") | out-null
"{0,-12} {1,-20} {2,-6} {3,-12}" -f  "Name", "Date Taken", "Make", "Model" 
Get-ChildItem *.jpg | foreach {
   $photo = New-Object -TypeName system.drawing.bitmap -ArgumentList $($_.FullName)
   $dts =  (ConvertTo-Chars $photo.GetPropertyItem(36867).value) -split " "
   $ds  = $dts[0] -split ":"
   $date = "{0}/{1}/{2} {3}" -f $($ds[2]), $($ds[1]), $($ds[0]), $($dts[1]) 
   $maker = ConvertTo-Chars $photo.GetPropertyItem(271).value
   $model = ConvertTo-Chars $photo.GetPropertyItem(272).value
   "{0,-12} {1,-20} {2,-6} {3,-12}" -f  $($_.Name), $date, $maker, $model 

}

 

Use –f to create a formatted string as a header.

Loop through the photos and create a bitmap object for the photo. The properties are held in a number of formats – they are explained in James’ blog that is commented in the beginning of the script. Luckily the ones we want are strings – but are held as byte arrays.

The camera maker and model are simply passed into the function that we use convert to a string.  The date we convert and then re-arrange from yyyy-mm-dd to dd/mm/yyyy format. We can then create a formatted script to display the data.

Technorati Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>