param( # Directory containing PNG images [string]$imageDir = "C:\path\to\your\images", # Output HTML file path [string]$outputHtml = "viewer.html" ) # Usage: .\Generate-Viewer-HTML.ps1 -imageDir "C:\images" -outputHtml "viewer.html" # Get all PNG files $images = Get-ChildItem -Path $imageDir -Filter *.png # Ensure outputHtml is just a file name if ($outputHtml -ne (Split-Path -Path $outputHtml -Leaf)) { throw "outputHtml must be a file name only (no path)." } # Save output HTML inside the image directory $outputPath = Join-Path -Path $imageDir -ChildPath $outputHtml # Generate HTML header $html = @" PNG Image Viewer "@ # Append image tags to HTML foreach ($img in $images) { $html += @"
$($img.Name)

$($img.Name)

"@ } # Close HTML tags $html += '
Full size image
' # Save the HTML file $html | Out-File -FilePath $outputPath -Encoding UTF8 Write-Host "Gallery created at $outputPath"