From 4432c09a61379ded1fc50c73b9d4007cd567e278 Mon Sep 17 00:00:00 2001
From: Markus Fleschutz <markus.fleschutz@gmail.com>
Date: Wed, 4 Sep 2024 10:33:05 +0200
Subject: [PATCH] Updated new-qrcode.ps1

---
 scripts/new-qrcode.ps1 | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/scripts/new-qrcode.ps1 b/scripts/new-qrcode.ps1
index a986b176..7e61996f 100755
--- a/scripts/new-qrcode.ps1
+++ b/scripts/new-qrcode.ps1
@@ -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])"