r/PowerShell • • Apr 02 '21
Question Export Image Dimensions in Powershell
Hi everyone. I would love some assistance here. Some of the work I see on this community is absolutely admirable; however, I'm an absolute NOOB with actually writing code in Powershell. I have a need to write a script that does the following: Exports image file names, and their respective dimensions from a specified path to a txt file.
I'd imagine the script would look similar to the results pulled from the DIR * > example.txt command, but with some code that appends the dimensions.
Side note - So far from my researching online, I found the following code that pulls width and height from a target file, but not the file name:
add-type -AssemblyName System.Drawing
$png = New-Object System.Drawing.Bitmap 'pathname\filename.PNG'
$png.PhysicalDimension
THANK YOU EVERYONE IN ADVANCE!
4
u/CHAOS_0704 Apr 02 '21
Probably want something like Get-ChildItem to grab everything within a path and then a For loop to cycle through each image file using the bit of code you already have.
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.1
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.1
2
u/Lee_Dailey [grin] Apr 05 '21
howdy antoinedag,
here's yet another ... [grin]
output ...
apparently the
.webptype aint supported by thesystem.drawingstuff. when i include that file type, thecatchblock outputs ...take care,
lee
1
u/BlackV Apr 02 '21
its was asked and answered a week or so ago in this very sub
1
u/Lee_Dailey [grin] Apr 05 '21
howdy antoinedag,
it looks like you used the New.Reddit
Inline Codebutton. it's [sometimes] 5th from the left & looks like</>.there are a few problems with that ...
the
inline codeformat is for [gasp! arg!] code that is inline with regular text.inline codeformatted text does NOT line wrap, nor does it side-scroll.for long-ish single lines OR for multiline code, please, use the ...
... button. it's [sometimes] the 12th one from the left & looks like an uppercase
Tin the upper left corner of a square..that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]
take care,
lee
2
u/[deleted] Apr 02 '21
[removed] — view removed comment