← Files Power BI DesktopARCHIVED FILE
scripts/Compare-PowerBIReportScreenshots.ps1
1.31 KB · Oct 2, 2026 · 00:32 UTC
param([string]$BaselinePath,[string]$CandidatePath,[string]$OutputPath,[switch]$Json)
$ErrorActionPreference='Stop';$result=[ordered]@{schema='codex.powerbi.visualPixelRegression.v1';status='NeedsScreenshotPair';baseline=$BaselinePath;candidate=$CandidatePath;changedPixelCount=$null;changedPercent=$null;nextAction='Supply matching PNG screenshots captured at the same viewport.'}
if($BaselinePath -and $CandidatePath -and(Test-Path -LiteralPath $BaselinePath)-and(Test-Path -LiteralPath $CandidatePath)){
Add-Type -AssemblyName System.Drawing;$a=[Drawing.Bitmap]::new((Resolve-Path $BaselinePath).Path);$b=[Drawing.Bitmap]::new((Resolve-Path $CandidatePath).Path);try{if($a.Width -ne $b.Width -or $a.Height -ne $b.Height){$result.status='ViewportMismatch'}else{$different=0;for($y=0;$y -lt $a.Height;$y++){for($x=0;$x -lt $a.Width;$x++){if($a.GetPixel($x,$y).ToArgb() -ne $b.GetPixel($x,$y).ToArgb()){$different++}}};$result.changedPixelCount=$different;$result.changedPercent=[math]::Round(($different/($a.Width*$a.Height))*100,4);$result.status=if($different -eq 0){'NoPixelDifference'}else{'VisualReviewRequired'}}}finally{$a.Dispose();$b.Dispose()}}
$object=[pscustomobject]$result;if($Json){$text=$object|ConvertTo-Json -Depth 6;if($OutputPath){Set-Content -LiteralPath $OutputPath -Value $text -Encoding UTF8};$text}else{$object}
SHA-256: 5ebfe4397385a8d200fbcf3a2f1008dbe562263efb893f865d8ea6ff79f5dea9