Update new-qrcode.ps1

This commit is contained in:
Markus Fleschutz 2022-08-29 13:47:19 +02:00
parent a6405ce64d
commit e4e34f34e1

View File

@ -1,6 +1,6 @@
<# <#
.SYNOPSIS .SYNOPSIS
Generates a new QR code image file Generates a QR code
.DESCRIPTION .DESCRIPTION
This PowerShell script generates a new QR code image file. This PowerShell script generates a new QR code image file.
.PARAMETER Text .PARAMETER Text
@ -26,8 +26,15 @@ try {
$ForegroundColor = "000000" $ForegroundColor = "000000"
$BackgroundColor = "ffffff" $BackgroundColor = "ffffff"
$FileFormat = "jpg" $FileFormat = "jpg"
$PathToRepo = "$PSScriptRoot/.." if ($IsLinux) {
$NewFile = "$PathToRepo/Data/qrcode.jpg" $PathToPics = Resolve-Path "$HOME/Pictures"
} else {
$PathToPics = [Environment]::GetFolderPath('MyPictures')
}
if (-not(Test-Path "$PathToPics" -pathType container)) {
throw "Pictures folder at 📂$Path doesn't exist (yet)"
}
$NewFile = "$PathToPics/QR_code.jpg"
$WebClient = new-object System.Net.WebClient $WebClient = new-object System.Net.WebClient
$WebClient.DownloadFile(("http://api.qrserver.com/v1/create-qr-code/?data=" + $Text + "&ecc=" + $ECC +` $WebClient.DownloadFile(("http://api.qrserver.com/v1/create-qr-code/?data=" + $Text + "&ecc=" + $ECC +`
@ -35,7 +42,7 @@ try {
"&color=" + $ForegroundColor + "&bgcolor=" + $BackgroundColor.Text + ` "&color=" + $ForegroundColor + "&bgcolor=" + $BackgroundColor.Text + `
"&format=" + $FileFormat), $NewFile) "&format=" + $FileFormat), $NewFile)
"✔️ new QR code image file written to: $NewFile" "✔️ saved new QR code image file to: $NewFile"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"