1

Following on closely from this Smart image search via Powershell

I have the following PowerShell script:-

Add-Type -Assembly System.Drawing

function Get-Image {
    $input | ForEach-Object { [Drawing.Image]::FromFile($_.FullName) }
}

Get-ChildItem -Path 'C:\Images' -Filter *.jpg -Recurse | Get-Image | ? { $_.Width -gt 1280 -or $_.Height -gt 1280 }

Problem is, this returns me a list of Image objects.

I basically want a list of file objects (which ultimately will be images) with a width OR height greater than 1280 pixels.

I need to somehow convert the image object back to a file object ?

The ultimatum is a list of filenames which are larger than 1280 pixels.

jpaugh
  • 6,634
  • 4
  • 38
  • 90
general exception
  • 4,202
  • 9
  • 54
  • 82

1 Answers1

3
function Get-Image{ 
process {
          $file = $_
          [Drawing.Image]::FromFile($_.FullName)  |
          ForEach-Object{           
            $_ | Add-Member -PassThru NoteProperty FullName ('{0}' -f $file.FullName)
          }
         }
}

then

Get-ChildItem -Path 'C:\Images' -Filter *.jpg -Recurse | Get-Image | ? { $_.Width -gt 1280 -or $_.Height -gt 1280 } | select -expa Fullname | get-item
CB.
  • 58,865
  • 9
  • 159
  • 159
  • This a) doesn't work, and b) still returns a list of Image objects. I have simplified the question. Goal is to end up with a list of FILE objects. – general exception Dec 06 '12 at 10:58
  • Excellent. Certainly does. Can you answer a couple of questions ? What is the significance of the process { } ? I understand that your keeping hold of the original file object passed in in $file and using it later on to get its FullName property. Also what is the significance of select -expa and get-item ? – general exception Dec 06 '12 at 11:08
  • 1
    @generalexception `process` process each input object piped in. `Select -expa propertyname` output just the property as `[string]` of the piped in object. the `get-item` is the trick with I can 'cast' the fullpath in a `[fileinfo]` type. – CB. Dec 06 '12 at 11:21