Update main.ps1

This commit is contained in:
egieb
2025-06-20 09:16:20 +00:00
committed by GitHub
parent 0a15fb645b
commit 1e0a55899d
+9 -9
View File
@@ -10,7 +10,6 @@ USAGE
3. Choose invert colors or not 3. Choose invert colors or not
4. Check console for results 4. Check console for results
#> #>
$URL = "$text" $URL = "$text"
$highC = 'y' $highC = 'y'
$inverse = 'n' $inverse = 'n'
@@ -25,12 +24,11 @@ function Generate-QRCodeURL {
param ([string]$URL,[int]$sizePercentage = 50) param ([string]$URL,[int]$sizePercentage = 50)
$EncodedURL = [uri]::EscapeDataString($URL) $EncodedURL = [uri]::EscapeDataString($URL)
$newSize = [math]::Round((300 * $sizePercentage) / 100) $newSize = [math]::Round((300 * $sizePercentage) / 100)
$QRCodeURL = "https://chart.googleapis.com/chart?chs=${newSize}x${newSize}&cht=qr&chl=$EncodedURL" # New working QR code API
$QRCodeURL = "https://api.qrserver.com/v1/create-qr-code/?size=${newSize}x${newSize}&data=$EncodedURL"
return $QRCodeURL return $QRCodeURL
} }
$QRCodeURL = Generate-QRCodeURL -URL $URL
function Download-QRCodeImage { function Download-QRCodeImage {
param ([string]$QRCodeURL) param ([string]$QRCodeURL)
$TempFile = [System.IO.Path]::GetTempFileName() + ".png" $TempFile = [System.IO.Path]::GetTempFileName() + ".png"
@@ -43,23 +41,25 @@ $QRCodeImageFile = Download-QRCodeImage -QRCodeURL $QRCodeURL
$QRCodeImage = [System.Drawing.Image]::FromFile($QRCodeImageFile) $QRCodeImage = [System.Drawing.Image]::FromFile($QRCodeImageFile)
$Bitmap = New-Object System.Drawing.Bitmap($QRCodeImage) $Bitmap = New-Object System.Drawing.Bitmap($QRCodeImage)
# Characters for different contrast and inverse modes
if (($highC -eq 'n') -and ($inverse -eq 'y')){ if (($highC -eq 'n') -and ($inverse -eq 'y')){
$Chars = @('░', '█') $Chars = @('░', '█')
} }
elseif (($highC -eq 'n') -and ($inverse -eq 'n')){ elseif (($highC -eq 'n') -and ($inverse -eq 'n')){
$Chars = @('█', '░') $Chars = @('█', '░')
} }
elseif (($highC -eq 'y') -and ($inverse -eq 'y')){
if (($highC -eq 'y') -and ($inverse -eq 'y')){ $Chars = @(' ', '')
$Chars = @(' ', '█')
} }
elseif (($highC -eq 'y') -and ($inverse -eq 'n')){ elseif (($highC -eq 'y') -and ($inverse -eq 'n')){
$Chars = @('█', ' ') $Chars = @('█', ' ')
} }
# Render QR code as characters
for ($y = 0; $y -lt $Bitmap.Height; $y += 2) { for ($y = 0; $y -lt $Bitmap.Height; $y += 2) {
for ($x = 0; $x -lt $Bitmap.Width; $x++) { for ($x = 0; $x -lt $Bitmap.Width; $x++) {
$Index = if ($Bitmap.GetPixel($x, $y).ToArgb() -eq -16777216) { 1 } else { 0 } # Check if the pixel is black or white $pixel = $Bitmap.GetPixel($x, $y)
$Index = if ($pixel.R -lt 128 -and $pixel.G -lt 128 -and $pixel.B -lt 128) { 1 } else { 0 }
Write-Host -NoNewline $Chars[$Index] Write-Host -NoNewline $Chars[$Index]
} }
Write-Host Write-Host