Just a quick script that lists information about the PNG and JPG images in a directory. I wrapped the important parts in a Start/Stop Transcript so that all output is logged to a file. I needed to get a feel for the image sizes and resolutions uploaded by users in our production environment in order to make recommendations for updates to the system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | add -type -AssemblyName System.Drawing; try { Start-Transcript ".\Get-ImageInformation-log.txt" -ErrorAction SilentlyContinue; } catch {} gci "C:\Demo\Images\*" -Include @( "*.png" , "*.jpg" ) | % { $img = New-Object System.Drawing.Bitmap $_.FullName; $obj = New-Object PSObject; Add-Member -InputObject $obj -MemberType NoteProperty -Name Name -Value $_.Name; Add-Member -InputObject $obj -MemberType NoteProperty -Name Length -Value $_.Length; Add-Member -InputObject $obj -MemberType NoteProperty -Name Height -Value $img .Height; Add-Member -InputObject $obj -MemberType NoteProperty -Name Width -Value $img .Width; Add-Member -InputObject $obj -MemberType NoteProperty -Name HRes -Value $img .HorizontalResolution; Add-Member -InputObject $obj -MemberType NoteProperty -Name VRes -Value $img .VerticalResolution; [Void] $img .Dispose(); $obj ; } | ft -AutoSize Name, @{n= 'Length' ;e={ "{0:N2} KB" -f ($_.Length / 1Kb)};align= 'right' }, Height, Width, HRes, VRes; try { Stop-Transcript -ErrorAction SilentlyContinue; } catch {} |
No comments:
Post a Comment