Updated new-qrcode.ps1

This commit is contained in:
Markus Fleschutz 2024-09-04 10:33:05 +02:00
parent 45bd64688e
commit 4432c09a61

View File

@ -1,48 +1,48 @@
<#
.SYNOPSIS
Generates a QR code
Creates a QR code
.DESCRIPTION
This PowerShell script generates a new QR code image file.
.PARAMETER Text
.PARAMETER text
Specifies the text to use
.PARAMETER ImageSize
.PARAMETER imageSize
Specifies the image size (width x height)
.PARAMETER fileFormat
Specifies the image file format
.EXAMPLE
PS> ./new-qrcode.ps1 "Fasten seatbelt" 500x500
PS> ./new-qrcode.ps1 "Fasten seatbelt" 500x500 JPG
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$Text = "", [string]$ImageSize = "")
param([string]$text = "", [string]$imageSize = "", [string]$fileFormat = "")
try {
if ($Text -eq "") { $Text = read-host "Enter text or URL" }
if ($ImageSize -eq "") { $ImageSize = read-host "Enter image size (e.g. 500x500)" }
if ($text -eq "") { $text = Read-Host "Enter text or URL" }
if ($imageSize -eq "") { $imageSize = Read-Host "Enter image size, e.g. 500x500" }
if ($fileFormat -eq "") { $fileFormat = Read-Host "Enter the image file format, e.g. JPG" }
$ECC = "M" # can be L, M, Q, H
$QuietZone = 1
$ForegroundColor = "000000"
$BackgroundColor = "ffffff"
$FileFormat = "jpg"
if ($IsLinux) {
$PathToPics = Resolve-Path "$HOME/Pictures"
$pathToPictures = Resolve-Path "$HOME/Pictures"
} else {
$PathToPics = [Environment]::GetFolderPath('MyPictures')
$pathToPictures = [Environment]::GetFolderPath('MyPictures')
}
if (-not(Test-Path "$PathToPics" -pathType container)) {
throw "Pictures folder at 📂$Path doesn't exist (yet)"
}
$NewFile = "$PathToPics/QR_code.jpg"
if (-not(Test-Path "$pathToPictures" -pathType container)) { throw "Pictures folder at 📂$Path doesn't exist (yet)" }
$newFile = "$pathToPictures/QR_code.$fileFormat"
$WebClient = new-object System.Net.WebClient
$WebClient.DownloadFile(("http://api.qrserver.com/v1/create-qr-code/?data=" + $Text + "&ecc=" + $ECC +`
"&size=" + $ImageSize + "&qzone=" + $QuietZone + `
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile(("http://api.qrserver.com/v1/create-qr-code/?data=" + $text + "&ecc=" + $ECC +`
"&size=" + $imageSize + "&qzone=" + $QuietZone + `
"&color=" + $ForegroundColor + "&bgcolor=" + $BackgroundColor.Text + `
"&format=" + $FileFormat), $NewFile)
"&format=" + $fileFormat), $newFile)
"✔️ saved new QR code image file to: $NewFile"
"✔️ New QR code saved as: $newFile"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"