PowerShell/scripts/new-qrcode.ps1

51 lines
1.7 KiB
PowerShell
Raw Normal View History

2023-10-31 12:48:22 +01:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2024-09-04 10:33:05 +02:00
Creates 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.
2024-09-04 10:33:05 +02:00
.PARAMETER text
2021-10-16 16:50:10 +02:00
Specifies the text to use
2024-09-04 10:33:05 +02:00
.PARAMETER imageSize
2021-10-16 16:50:10 +02:00
Specifies the image size (width x height)
2024-09-04 10:33:05 +02:00
.PARAMETER fileFormat
Specifies the image file format
2021-07-13 21:10:02 +02:00
.EXAMPLE
2024-09-04 10:33:05 +02:00
PS> ./new-qrcode.ps1 "Fasten seatbelt" 500x500 JPG
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
#>
2024-09-04 10:33:05 +02:00
param([string]$text = "", [string]$imageSize = "", [string]$fileFormat = "")
2021-02-18 20:17:55 +01:00
2020-12-30 16:40:07 +01:00
try {
2024-09-04 10:33:05 +02:00
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" }
2021-07-15 15:51:22 +02:00
2021-02-12 12:19:44 +01:00
$ECC = "M" # can be L, M, Q, H
$QuietZone = 1
$ForegroundColor = "000000"
$BackgroundColor = "ffffff"
2022-08-29 13:47:19 +02:00
if ($IsLinux) {
2024-09-04 10:33:05 +02:00
$pathToPictures = Resolve-Path "$HOME/Pictures"
2022-08-29 13:47:19 +02:00
} else {
2024-09-04 10:33:05 +02:00
$pathToPictures = [Environment]::GetFolderPath('MyPictures')
2022-08-29 13:47:19 +02:00
}
2024-09-04 10:33:05 +02:00
if (-not(Test-Path "$pathToPictures" -pathType container)) { throw "Pictures folder at 📂$Path doesn't exist (yet)" }
$newFile = "$pathToPictures/QR_code.$fileFormat"
2021-02-12 12:19:44 +01:00
2024-09-04 10:33:05 +02: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 + `
2020-12-30 16:40:07 +01:00
"&color=" + $ForegroundColor + "&bgcolor=" + $BackgroundColor.Text + `
2024-09-04 10:33:05 +02:00
"&format=" + $fileFormat), $newFile)
2021-02-10 19:25:48 +01:00
2024-09-04 10:33:05 +02:00
"✔️ New QR code saved as: $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
}