How can I get the detail informations from a specific .png file in PowerShell?
Like dimensions, bit depth and size.
When you want to read the entire contents of a text file, the easiest way is to use the built-in Get-Content function. When you execute this command, the contents of this file will be displayed in your command prompt or the PowerShell ISE screen, depending on where you execute it.
Once you have saved the script, go to the output pane and run the script, as shown in the image below. Note, the PowerShell cmdlet for print is “Out-Printer“. The “Out-Printer” cmdlet of the PowerShell will only send data to your printer. Now, we will move towards printing a file using this “cmdlet“.
You can use the Start-Process (or its start alias) command. It will open your image with the default application set to open png files (or ask you to choose one if no default image viewer is set).
You might want to use the PowershellPack Module which contains get-image:
PS D:\> import-module psimagetools
PS D:\> get-item .\fig410.png | get-image
FullName : D:\fig410.png
FormatID : {B96B3CAF-0728-11D3-9D7B-0000F81EF32E}
FileExtension : png
FileData : System.__ComObject
ARGBData : System.__ComObject
Height : 450
Width : 700
HorizontalResolution : 96,0119934082031
VerticalResolution : 96,0119934082031
PixelDepth : 32
IsIndexedPixelFormat : False
IsAlphaPixelFormat : True
IsExtendedPixelFormat : False
IsAnimated : False
FrameCount : 1
ActiveFrame : 1
Properties : System.__ComObject
or you could use Wia.ImageFile directly (which is how the get-image function does it) this way:
PS D:\> $image = New-Object -ComObject Wia.ImageFile
PS D:\> $image.loadfile("D:\fig410.png")
PS D:\> $image
FormatID : {B96B3CAF-0728-11D3-9D7B-0000F81EF32E}
FileExtension : png
FileData : System.__ComObject
ARGBData : System.__ComObject
Height : 450
Width : 700
HorizontalResolution : 96,0119934082031
VerticalResolution : 96,0119934082031
PixelDepth : 32
IsIndexedPixelFormat : False
IsAlphaPixelFormat : True
IsExtendedPixelFormat : False
IsAnimated : False
FrameCount : 1
ActiveFrame : 1
Properties : System.__ComObject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With