PowerShell/scripts/new-qrcode.ps1

51 lines
1.5 KiB
PowerShell
Raw Normal View History

2023-10-31 12:48:22 +01:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2022-08-29 13:47:19 +02:00
Generates a QR code
2021-10-04 21:29:23 +02:00
.DESCRIPTION
2022-01-29 12:47:46 +01:00
This PowerShell script generates a new QR code image file.
2021-10-16 16:50:10 +02:00
.PARAMETER Text
Specifies the text to use
.PARAMETER ImageSize
Specifies the image size (width x height)
2021-07-13 21:10:02 +02:00
.EXAMPLE
2023-08-06 21:35:36 +02:00
PS> ./new-qrcode.ps1 "Fasten seatbelt" 500x500
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-29 12:47:46 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2020-12-30 16:40:07 +01:00
#>
2021-07-15 15:51:22 +02:00
param([string]$Text = "", [string]$ImageSize = "")
2021-02-18 20:17:55 +01:00
2020-12-30 16:40:07 +01:00
try {
2021-07-15 15:51:22 +02:00
if ($Text -eq "") { $Text = read-host "Enter text or URL" }
if ($ImageSize -eq "") { $ImageSize = read-host "Enter image size (e.g. 500x500)" }
2021-02-12 12:19:44 +01:00
$ECC = "M" # can be L, M, Q, H
$QuietZone = 1
$ForegroundColor = "000000"
$BackgroundColor = "ffffff"
$FileFormat = "jpg"
2022-08-29 13:47:19 +02:00
if ($IsLinux) {
$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"
2021-02-12 12:19:44 +01:00
2020-12-30 16:40:07 +01:00
$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)
2021-02-10 19:25:48 +01:00
2022-08-29 13:47:19 +02:00
"✔️ saved new QR code image file to: $NewFile"
2021-09-27 10:09:45 +02:00
exit 0 # success
2020-12-30 16:40:07 +01:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-30 16:40:07 +01:00
exit 1
}