|
| 1 | +$chromiumNames = 'chromium','chrome','msedge' |
| 2 | +foreach ($browserName in $chromiumNames) { |
| 3 | + $chromiumCommand = |
| 4 | + $ExecutionContext.SessionState.InvokeCommand.GetCommand($browserName,'Application') |
| 5 | + if (-not $chromiumCommand) { |
| 6 | + $chromiumCommand = |
| 7 | + Get-Process -Name $browserName -ErrorAction Ignore | |
| 8 | + Select-Object -First 1 -ExpandProperty Path |
| 9 | + } |
| 10 | + if ($chromiumCommand) { break } |
| 11 | +} |
| 12 | +if (-not $chromiumCommand) { |
| 13 | + Write-Error "No Chromium-based browser found. Please install one of: $($chromiumNames -join ', ')" |
| 14 | + return |
| 15 | +} |
| 16 | + |
| 17 | +$pngRasterizer = $this.Canvas -replace '/\*Insert-Post-Processing-Here\*/', @' |
| 18 | + const dataUrl = await canvas.toDataURL('image/webp') |
| 19 | + console.log(dataUrl) |
| 20 | + |
| 21 | + const newImage = document.createElement('img') |
| 22 | + newImage.src = dataUrl |
| 23 | + document.body.appendChild(newImage) |
| 24 | +'@ |
| 25 | + |
| 26 | + |
| 27 | +$appDataRoot = [Environment]::GetFolderPath("ApplicationData") |
| 28 | +$appDataPath = Join-Path $appDataRoot 'Turtle' |
| 29 | +$filePath = Join-Path $appDataPath 'Turtle.raster.html' |
| 30 | +$null = New-Item -ItemType File -Force -Path $filePath -Value ( |
| 31 | + $pngRasterizer -join [Environment]::NewLine |
| 32 | +) |
| 33 | +# $pngRasterizer > $filePath |
| 34 | + |
| 35 | +$headlessArguments = @( |
| 36 | + '--headless', # run in headless mode |
| 37 | + '--dump-dom', # dump the DOM to stdout |
| 38 | + '--disable-gpu', # disable GPU acceleration |
| 39 | + '--no-sandbox' # disable the sandbox if running in CI/CD |
| 40 | +) |
| 41 | + |
| 42 | +$chromeOutput = & $chromiumCommand @headlessArguments "$filePath" | Out-String |
| 43 | +if ($chromeOutput -match '<img\ssrc="data:image/\w+;base64,(?<b64>[^"]+)') { |
| 44 | + ,[Convert]::FromBase64String($matches.b64) |
| 45 | +} |
0 commit comments