Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thomas694/2145b9b333669f8efe72b51fcbc1c8b7 to your computer and use it in GitHub Desktop.

Select an option

Save thomas694/2145b9b333669f8efe72b51fcbc1c8b7 to your computer and use it in GitHub Desktop.
List all 48- or 64-bit PNGs in a folder tree

List all 48- or 64-bit PNGs in a folder tree

The script lists all 48-/64-bit PNGs in a folder tree, optionally as ready-made ImageMagick convert commands.

The attached powershell script searches all PNG files in the specified folder (including its subfolders) and outputs their filenames. Optionally with the 2nd parameter commands the filenames are embedded in command lines* for ImageMagick's Convert tool,
e.g.

C:\ImageMagick\convert.exe "D:\Folder\Image_64bit.png" -format png -depth 8 "D:\Folder\Image_64bit.png64.png"

*You have to adjust the path to your ImageMagick installation folder in the script once.

When you execute the commands the files are converted to 8-bit PNGs and saved as Image.png48.png resp. Image.png64.png.

The script makes use of the function Get-FileMetaData(link) which retrieves metadata information from files.

function Get-FileMetaData {
<#
.SYNOPSIS
Small function that gets metadata information from file providing similar output to what Explorer shows when viewing file
.DESCRIPTION
Small function that gets metadata information from file providing similar output to what Explorer shows when viewing file
.PARAMETER File
FileName or FileObject
.EXAMPLE
Get-ChildItem -Path $Env:USERPROFILE\Desktop -Force | Get-FileMetaData | Out-HtmlView -ScrollX -Filtering -AllProperties
.EXAMPLE
Get-ChildItem -Path $Env:USERPROFILE\Desktop -Force | Where-Object { $_.Attributes -like '*Hidden*' } | Get-FileMetaData | Out-HtmlView -ScrollX -Filtering -AllProperties
.NOTES
#>
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipeline)][Object] $File,
[switch] $Signature
)
Process {
foreach ($F in $File) {
$MetaDataObject = [ordered] @{}
if ($F -is [string]) {
$FileInformation = Get-ItemProperty -Path $F
} elseif ($F -is [System.IO.DirectoryInfo]) {
#Write-Warning "Get-FileMetaData - Directories are not supported. Skipping $F."
continue
} elseif ($F -is [System.IO.FileInfo]) {
$FileInformation = $F
} else {
Write-Warning "Get-FileMetaData - Only files are supported. Skipping $F."
continue
}
$ShellApplication = New-Object -ComObject Shell.Application
$ShellFolder = $ShellApplication.Namespace($FileInformation.Directory.FullName)
$ShellFile = $ShellFolder.ParseName($FileInformation.Name)
$MetaDataProperties = [ordered] @{}
0..400 | ForEach-Object -Process {
$DataValue = $ShellFolder.GetDetailsOf($null, $_)
$PropertyValue = (Get-Culture).TextInfo.ToTitleCase($DataValue.Trim()).Replace(' ', '')
if ($PropertyValue -ne '') {
$MetaDataProperties["$_"] = $PropertyValue
}
}
foreach ($Key in $MetaDataProperties.Keys) {
$Property = $MetaDataProperties[$Key]
$Value = $ShellFolder.GetDetailsOf($ShellFile, [int] $Key)
if ($Property -in 'Attributes', 'Folder', 'Type', 'SpaceFree', 'TotalSize', 'SpaceUsed') {
continue
}
If (($null -ne $Value) -and ($Value -ne '')) {
$MetaDataObject["$Property"] = $Value
}
}
if ($FileInformation.VersionInfo) {
$SplitInfo = ([string] $FileInformation.VersionInfo).Split([char]13)
foreach ($Item in $SplitInfo) {
$Property = $Item.Split(":").Trim()
if ($Property[0] -and $Property[1] -ne '') {
$MetaDataObject["$($Property[0])"] = $Property[1]
}
}
}
$MetaDataObject["Attributes"] = $FileInformation.Attributes
$MetaDataObject['IsReadOnly'] = $FileInformation.IsReadOnly
$MetaDataObject['IsHidden'] = $FileInformation.Attributes -like '*Hidden*'
$MetaDataObject['IsSystem'] = $FileInformation.Attributes -like '*System*'
if ($Signature) {
$DigitalSignature = Get-AuthenticodeSignature -FilePath $FileInformation.Fullname
$MetaDataObject['SignatureCertificateSubject'] = $DigitalSignature.SignerCertificate.Subject
$MetaDataObject['SignatureCertificateIssuer'] = $DigitalSignature.SignerCertificate.Issuer
$MetaDataObject['SignatureCertificateSerialNumber'] = $DigitalSignature.SignerCertificate.SerialNumber
$MetaDataObject['SignatureCertificateNotBefore'] = $DigitalSignature.SignerCertificate.NotBefore
$MetaDataObject['SignatureCertificateNotAfter'] = $DigitalSignature.SignerCertificate.NotAfter
$MetaDataObject['SignatureCertificateThumbprint'] = $DigitalSignature.SignerCertificate.Thumbprint
$MetaDataObject['SignatureStatus'] = $DigitalSignature.Status
$MetaDataObject['IsOSBinary'] = $DigitalSignature.IsOSBinary
}
[PSCustomObject] $MetaDataObject
}
}
}
if (!$args[0]) {
Write-Host "No folder specified!"
Exit
}
if ($args[1] -eq "commands") {
Get-ChildItem -Path $args[0] -Recurse -Filter *.png | Get-FileMetaData | where-object -filterscript {($_.BitDepth -eq 64) -or ($_.BitDepth -eq 48)} | Sort-Object -Property BitDepth,Path |
ForEach-Object { Write-Output "C:\ImageMagick\convert.exe ""$($_.Path)"" -format png -depth 8 ""$($_.Path)$($_.BitDepth).png""" }
} else {
Get-ChildItem -Path $args[0] -Recurse -Filter *.png | Get-FileMetaData | where-object -filterscript {($_.BitDepth -eq 64) -or ($_.BitDepth -eq 48)} | Sort-Object -Property BitDepth,Path | Select-Object -Property BitDepth,Path
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment