-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView-ImageMetadata.ps1
More file actions
77 lines (63 loc) · 2.53 KB
/
View-ImageMetadata.ps1
File metadata and controls
77 lines (63 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# View Image Metadata
# Usage: .\View-ImageMetadata.ps1 "path\to\image.png"
param(
[Parameter(Mandatory=$true)]
[string]$ImagePath
)
if (-not (Test-Path $ImagePath)) {
Write-Host "Error: File not found: $ImagePath" -ForegroundColor Red
exit
}
$extension = [System.IO.Path]::GetExtension($ImagePath).ToLower()
if ($extension -eq ".svg") {
# SVG - Just show the metadata section
Write-Host "`nSVG Metadata from: $ImagePath" -ForegroundColor Cyan
Write-Host ("=" * 60) -ForegroundColor Gray
$content = Get-Content $ImagePath -Raw
# Extract metadata from desc tag
if ($content -match '<g id="visualization-parameters"[^>]*>.*?<desc>(.*?)</desc>') {
Write-Host $matches[1] -ForegroundColor Green
} else {
Write-Host "No visualization metadata found in SVG" -ForegroundColor Yellow
}
} else {
# PNG/JPEG/BMP - Use System.Drawing
Add-Type -AssemblyName System.Drawing
try {
$img = [System.Drawing.Image]::FromFile($ImagePath)
Write-Host "`nImage Metadata from: $ImagePath" -ForegroundColor Cyan
Write-Host ("=" * 60) -ForegroundColor Gray
Write-Host "Size: $($img.Width) x $($img.Height) pixels" -ForegroundColor Yellow
Write-Host "Format: $($img.RawFormat)" -ForegroundColor Yellow
Write-Host "`nEmbedded Metadata:" -ForegroundColor Magenta
$foundMetadata = $false
foreach ($prop in $img.PropertyItems) {
$value = [System.Text.Encoding]::ASCII.GetString($prop.Value).TrimEnd("`0")
switch ($prop.Id) {
0x010E {
Write-Host "`n[Image Description]" -ForegroundColor Cyan
Write-Host $value -ForegroundColor White
$foundMetadata = $true
}
0x0131 {
Write-Host "`n[Software]" -ForegroundColor Cyan
Write-Host $value -ForegroundColor White
$foundMetadata = $true
}
0x9286 {
Write-Host "`n[Full Parameters]" -ForegroundColor Cyan
Write-Host $value -ForegroundColor Green
$foundMetadata = $true
}
}
}
if (-not $foundMetadata) {
Write-Host "`nNo custom metadata found in this image." -ForegroundColor Yellow
}
$img.Dispose()
}
catch {
Write-Host "Error reading image: $_" -ForegroundColor Red
}
}
Write-Host "`n"