Types/Turtle/get_JPEG.ps1
$chromiumNames = 'chromium','chrome','msedge' foreach ($browserName in $chromiumNames) { $chromiumCommand = $ExecutionContext.SessionState.InvokeCommand.GetCommand($browserName,'Application') if (-not $chromiumCommand) { $chromiumCommand = Get-Process -Name $browserName -ErrorAction Ignore | Select-Object -First 1 -ExpandProperty Path } if ($chromiumCommand) { break } } if (-not $chromiumCommand) { Write-Error "No Chromium-based browser found. Please install one of: $($chromiumNames -join ', ')" return } $pngRasterizer = $this.Canvas -replace '/\*Insert-Post-Processing-Here\*/', @' const dataUrl = await canvas.toDataURL('image/jpeg') console.log(dataUrl) const newImage = document.createElement('img') newImage.src = dataUrl document.body.appendChild(newImage) '@ $appDataRoot = [Environment]::GetFolderPath("ApplicationData") $appDataPath = Join-Path $appDataRoot 'Turtle' $filePath = Join-Path $appDataPath 'Turtle.raster.html' $null = New-Item -ItemType File -Force -Path $filePath -Value ( $pngRasterizer -join [Environment]::NewLine ) # $pngRasterizer > $filePath $headlessArguments = @( '--headless', # run in headless mode '--dump-dom', # dump the DOM to stdout '--disable-gpu', # disable GPU acceleration '--no-sandbox' # disable the sandbox if running in CI/CD ) $chromeOutput = & $chromiumCommand @headlessArguments "$filePath" | Out-String if ($chromeOutput -match '<img\ssrc="data:image/\w+;base64,(?<b64>[^"]+)') { ,[Convert]::FromBase64String($matches.b64) } |