List of images exceeding 4M pixels with Powershell
First you want to select your file types as explained in this question so you would want something like this using -Include
rather than -Filter
Get-ChildItem -Path 'C:\imagefolder' -Include('*.jpg','*.png','.gif') -Recurse
From these you want to select only those over 4 million pixels. You can use the Get-Image
function in your question - if you Select *
on its output you can see what it gives you.
PS C:\> Get-ChildItem -Path 'C:\imagefolder' -Include('*.jpg','*.png','.gif') -Recurse | Get-Image | Select *
FullName : C:\imagefolder\DSC00237.JPG
Tag :
PhysicalDimension : {Width=5152, Height=3864}
Size : {Width=5152, Height=3864}
Width : 5152
Height : 3864
HorizontalResolution : 350
VerticalResolution : 350
Flags : 77840
RawFormat : [ImageFormat: b96b3cae-0728-11d3-9d7b-0000f81ef32e]
PixelFormat : Format24bppRgb
Palette : System.Drawing.Imaging.ColorPalette
FrameDimensionsList : {7462dc86-6180-4c7e-8e3f-ee7333a7a483}
PropertyIdList : {270, 271, 272, 274...}
PropertyItems : {270, 271, 272, 274...}
So you see it has the Width
and Height
so (as in your question) you can work out number of pixels by multiplying and then select only those objects where this number is greater than 4m with Where { ($_.Width * $_.Height) -gt 4000000 }
Finally you want to Select
what to display from the available properties. You can rename calculated fields as described here so for name and pixels you would want to Select Fullname, @{N='Pixels'; E={ ($_.Width * $_.Height) }}
to give
Get-ChildItem -Path 'C:\imagefolder' -Include('*.jpg','*.png','.gif') -Recurse | `
Get-Image | Where { ($_.Width * $_.Height) -gt 4000000 } | `
Select Fullname, @{N='Pixels'; E={ ($_.Width * $_.Height) }}
After changing the path and number of pixels this gives output like this :
PS D:\> Add-Type -Assembly System.Drawing
PS D:\> function Get-Image{
>> process {
>> $file = $_
>> [Drawing.Image]::FromFile($_.FullName) |
>> ForEach-Object{
>> $_ | Add-Member -PassThru NoteProperty FullName ('{0}' -f $file.FullName)
>> }
>> }
>> }
PS D:\> Get-ChildItem -Path 'D:\Hali\OneDrive\Pictures\2004' -Include('*.jpg','*.png','.gif') -Recurse | Get-Image | Where { ($_.Width * $_.Height) -gt 100000 } | Select Fullname, @{N='Pixels'; E={ ($_.Width * $_.Height) }}
FullName Pixels
-------- ------
D:\Hali\OneDrive\Pictures\2004\06\PICT0262 (2014_05_15 20_48_01 UTC).jpg 5038848
D:\Hali\OneDrive\Pictures\2004\06\PICT0264 (2014_05_15 20_48_01 UTC).jpg 5038848
D:\Hali\OneDrive\Pictures\2004\06\PICT0265 (2014_05_15 20_48_01 UTC).jpg 5038848
D:\Hali\OneDrive\Pictures\2004\06\PICT0266 (2014_05_15 20_48_01 UTC).jpg 5038848