Hi Guys,
I have two codes with me. I now want to merge this two codes together.
Code:1 - This will give you the image metadata info in a excel sheet:
Write-Host "Starting the script...Please wait untill the extraction is complete"
Function Get-FileMetaData
{
Param([string]$folder)
foreach($sFolder in $folder)
{
$a = 0
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace($sFolder)
foreach ($File in $objFolder.items())
{
$FileMetaData = New-Object PSOBJECT
for ($a ; $a -le 266; $a++)
{
if($objFolder.getDetailsOf($File, $a))
{
$hash += @{$($objFolder.getDetailsOf($objFolder.items, $a)) = $($objFolder.getDetailsOf($File, $a) -replace([char]8206,“”) -replace([char]8207,“”) ) }
$FileMetaData | Add-Member $hash
$hash.clear()
} #end if
} #end for
$a=0
$FileMetaData
} #end foreach $file
} #end foreach $sfolder
} #end Get-FileMetaData
$picdata = Get-FileMetaData $Env:userprofile\Desktop\image |select name,‘Item type’,size, height,width,‘horizontal resolution’,‘vertical resolution’,‘color depth’, ‘Bit depth’,‘jpeg_colorspace’
$picdata | Export-csv $Env:userprofile\Desktop\image\ImageData.csv
Code 2 - This will give the “colorspace” info of an image through a form. The user has to select each image individually to find this property:
###########################################################
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Main Form
$mainForm = New-Object System.Windows.Forms.Form
$mainForm.Font = “Comic Sans MS,8.25”
$mainForm.Text = “ColorSpace Extraction”
$mainForm.ForeColor = “White”
$mainForm.BackColor = “DarkBlue”
$mainForm.width = 400
$mainForm.height = 480
Title Label
$titleLabel = New-Object System.Windows.Forms.Label
$titleLabel.Font = “Comic Sans MS,12”
$titleLabel.ForeColor = “Yellow”
$titleLabel.Location = “95,10”
$titleLabel.Size = “300,30”
$titleLabel.Text = “ColorSpace Extraction”
$mainForm.Controls.Add($titleLabel)
Form Labels
$colorSpaceLabel = New-Object System.Windows.Forms.Label
$colorSpaceLabel.Font = “Comic Sans MS,8”
$colorSpaceLabel.Location = “20,100”
$colorSpaceLabel.Size = “120,15”
$colorSpaceLabel.Text = “Color Space”
$mainForm.Controls.Add($colorSpaceLabel)
Form TextBoxes
$colorSpaceTextBox = New-Object System.Windows.Forms.TextBox
$colorSpaceTextBox.Font = “Comic Sans MS,8”
$colorSpaceTextBox.Location = “140,100”
$colorSpaceTextBox.Size = “200,15”
$mainForm.Controls.Add($colorSpaceTextBox)
SelectFile Button
$imageFileNameButton = New-Object System.Windows.Forms.Button
$imageFileNameButton.Font = “Comic Sans MS,8”
$imageFileNameButton.Location = “30,212”
$imageFileNameButton.Size = “75,23”
$imageFileNameButton.ForeColor = “DarkBlue”
$imageFileNameButton.BackColor = “White”
$imageFileNameButton.Text = “Select File”
$imageFileNameButton.add_Click({selectFile})
$mainForm.Controls.Add($imageFileNameButton)
Exit Button
$exitButton = New-Object System.Windows.Forms.Button
$exitButton.Location = “270,212”
$exitButton.Size = “75,23”
$exitButton.ForeColor = “Red”
$exitButton.BackColor = “White”
$exitButton.Text = “Exit”
$exitButton.add_Click({$mainForm.close()})
$mainForm.Controls.Add($exitButton)
function selectFile {
$selectForm = New-Object System.Windows.Forms.OpenFileDialog
$selectForm.Filter = “All Files (.)|.”
$selectForm.InitialDirectory = "."
$selectForm.Title = “Select a Image File to Process”
$getKey = $selectForm.ShowDialog()
If ($getKey -eq “OK”) {
$filename = $selectForm.FileName
$photo = [System.Drawing.Image]::FromFile($filename)
# Color Space
$colorProperty = $photo.GetPropertyItem(40961)
if ($colorProperty -ne $null){
$colorSpace = [System.BitConverter]::ToUInt16($colorProperty.Value, 0)}
if ($colorSpace -eq "1") {$colorSpace = "sRGB"}
if ($colorSpace -eq "2") {$colorSpace = "Adobe RGB"}
if ($colorSpace -eq "65535") {$colorSpace = "Uncalibrated"}
$colorSpaceTextBox.Text = $colorSpace
} # End $getkey If
} # End SelectFile Function
function MakeNumber {
$first =$args[0].value[0] + 256 * $args[0].value[1] + 65536 * $args[0].value[2] + 16777216 * $args[0].value[3] ;
$second=$args[0].value[4] + 256 * $args[0].value[5] + 65536 * $args[0].value[6] + 16777216 * $args[0].value[7] ;
if ($first -gt 2147483648) {$first = $first - 4294967296} ;
if ($second -gt 2147483648) {$second= $second - 4294967296} ;
if ($second -eq 0) {$second= 1} ;
if (($first –eq 1) -and ($second -ne 1)) {
write-output (“1/” + $second)}
else {
write-output ($first / $second)}
} # End Function MakeNumber
[void] $mainForm.ShowDialog()
This is what I wanna do:
I want to merge the colorspace code into code 1 so that the result will be added into the excel. (without the form interface) Can some one help me on where I should I add the colorspace code in Code 1 to accomplish this?