@@ -856,6 +856,57 @@ if ($VerbosePreference -ne 'SilentlyContinue') {
856856}
857857 </SetScriptBlock >
858858 </ScriptProperty >
859+ <ScriptProperty >
860+ <Name >JPEG</Name >
861+ <GetScriptBlock >
862+ $chromiumNames = 'chromium','chrome','msedge'
863+ foreach ($browserName in $chromiumNames) {
864+ $chromiumCommand =
865+ $ExecutionContext.SessionState.InvokeCommand.GetCommand($browserName,'Application')
866+ if (-not $chromiumCommand) {
867+ $chromiumCommand =
868+ Get-Process -Name $browserName -ErrorAction Ignore |
869+ Select-Object -First 1 -ExpandProperty Path
870+ }
871+ if ($chromiumCommand) { break }
872+ }
873+ if (-not $chromiumCommand) {
874+ Write-Error "No Chromium-based browser found. Please install one of: $($chromiumNames -join ', ')"
875+ return
876+ }
877+
878+ $pngRasterizer = $this.Canvas -replace '/\*Insert-Post-Processing-Here\*/', @'
879+ const dataUrl = await canvas.toDataURL('image/jpeg')
880+ console.log(dataUrl)
881+
882+ const newImage = document.createElement('img')
883+ newImage.src = dataUrl
884+ document.body.appendChild(newImage)
885+ '@
886+
887+
888+ $appDataRoot = [Environment]::GetFolderPath("ApplicationData")
889+ $appDataPath = Join-Path $appDataRoot 'Turtle'
890+ $filePath = Join-Path $appDataPath 'Turtle.raster.html'
891+ $null = New-Item -ItemType File -Force -Path $filePath -Value (
892+ $pngRasterizer -join [Environment]::NewLine
893+ )
894+ # $pngRasterizer > $filePath
895+
896+ $headlessArguments = @(
897+ '--headless', # run in headless mode
898+ '--dump-dom', # dump the DOM to stdout
899+ '--disable-gpu', # disable GPU acceleration
900+ '--no-sandbox' # disable the sandbox if running in CI/CD
901+ )
902+
903+ $chromeOutput = & $chromiumCommand @headlessArguments "$filePath" | Out-String
904+ if ($chromeOutput -match '< img\ssrc="data:image/\w+;base64,(?< b64> [^"]+)') {
905+ ,[Convert]::FromBase64String($matches.b64)
906+ }
907+
908+ </GetScriptBlock >
909+ </ScriptProperty >
859910 <ScriptProperty >
860911 <Name >Mask</Name >
861912 <GetScriptBlock >
0 commit comments