Skip to content

Commit

Permalink
Merge pull request #1 from T0biii/master
Browse files Browse the repository at this point in the history
Add new Function New-PSOneQRCodeText and some more things
  • Loading branch information
TobiasPSP authored Sep 1, 2020
2 parents 5e027e3 + bf4d724 commit 03d6468
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 2 deletions.
61 changes: 61 additions & 0 deletions QRCodeGenerator/2.3/New-PSOneQRCode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function New-PSOneQRCode
{
<#
.SYNOPSIS
Creates a QR code graphic
.DESCRIPTION
Creates a QR code graphic in png format that - when scanned by a smart device
.PARAMETER Payload
The Payload for the QR code
.PARAMETER Width
Height and Width of generated graphics (in pixels). Default is 100.
.PARAMETER Show
Opens the generated QR code in associated program
.PARAMETER OutPath
Path to generated png file. When omitted, a temporary file name is used.
.EXAMPLE
New-PSOneQRCode -payload $payload -Width $width -Show -OutPath $OutPath
Creates a QR code png graphics on your desktop, and opens it with the associated program
.NOTES
Compatible with all PowerShell versions including PowerShell 6/Core
Uses binaries from https://github.com/codebude/QRCoder/wiki
.LINK
https://github.com/TobiasPSP/Modules.QRCodeGenerator
#>

[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[string]
$payload,

[Parameter(Mandatory)]
[bool]
$Show,

[ValidateRange(10,2000)]
[int]
$Width = 100,

[string]
$OutPath = "$env:temp\qrcode.png"
)


$generator = New-Object -TypeName QRCoder.QRCodeGenerator
$data = $generator.CreateQrCode($payload, 'Q')
$code = new-object -TypeName QRCoder.PngByteQRCode -ArgumentList ($data)
$byteArray = $code.GetGraphic($Width)
[System.IO.File]::WriteAllBytes($outPath, $byteArray)

if ($Show) { Invoke-Item -Path $outPath }
}
82 changes: 82 additions & 0 deletions QRCodeGenerator/2.3/New-PSOneQRCodeGeolocation.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
function New-PSOneQRCodeGeolocation
{
<#
.SYNOPSIS
Creates a QR code graphic containing a geo location
.DESCRIPTION
Creates a QR code graphic in png format that - when scanned by a smart device - opens the geo location in a browser.
.PARAMETER Latitude
The location latitude
.PARAMETER Longitude
The location longitude
.PARAMETER Width
Height and Width of generated graphics (in pixels). Default is 100.
.PARAMETER Show
Opens the generated QR code in associated program
.PARAMETER OutPath
Path to generated png file. When omitted, a temporary file name is used.
.EXAMPLE
New-PSOneQRCodeGeoLocation -Latitude 21.12 -Longitude 22.87 -Width 200 -Show -OutPath "$home\Desktop\qr.png"
Creates a QR code png graphics on your desktop, and opens it with the associated program
.NOTES
Compatible with all PowerShell versions including PowerShell 6/Core
Uses binaries from https://github.com/codebude/QRCoder/wiki
.LINK
https://github.com/TobiasPSP/Modules.QRCodeGenerator
#>

[CmdletBinding(DefaultParameterSetName="Address")]
param
(
[Parameter(Mandatory,ParameterSetName='Location')]
[double]
$Latitude,

[Parameter(Mandatory,ParameterSetName='Location')]
[double]
$Longitude,

[Parameter(Mandatory,ParameterSetName='Address')]
[string]
$Address,

[ValidateRange(10,2000)]
[int]
$Width = 100,

[Switch]
$Show,

[string]
$OutPath = "$env:temp\qrcode.png"
)

if ($PSCmdlet.ParameterSetName -eq "Address")
{
$AddressEncoded = [System.Net.WebUtility]::UrlEncode($Address)

$null = Invoke-RestMethod -SessionVariable session -Uri "https://geocode.xyz"
$data = Invoke-RestMethod -WebSession $session -Uri "https://geocode.xyz/${AddressEncoded}?json=1"
if ($null -eq $data.error)
{
throw "Address not found. $($data.Error.Description)"
}
$Latitude =$data.latt
$Longitude = $data.longt
}

$payload = @"
geo:$Latitude,$Longitude
"@

New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath
}
52 changes: 52 additions & 0 deletions QRCodeGenerator/2.3/New-PSOneQRCodeText.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function New-PSOneQRCodeText
{
<#
.SYNOPSIS
Creates a QR code graphic containing for a Text
.DESCRIPTION
Creates a QR code graphic in png format that - when scanned by a smart device - shows a text.
.PARAMETER Text
The Text to show
.PARAMETER Show
Opens the generated QR code in associated program
.PARAMETER OutPath
Path to generated png file. When omitted, a temporary file name is used.
.EXAMPLE
New-PSOneQRCodeText -Text tobiaspsp -Width 200 -Show -OutPath "$home\Desktop\qr.png"
Creates a QR code png graphics on your desktop, and opens it with the associated program
.NOTES
Compatible with all PowerShell versions including PowerShell 6/Core
Uses binaries from https://github.com/codebude/QRCoder/wiki
.LINK
https://github.com/TobiasPSP/Modules.QRCodeGenerator
#>

[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[string]
$Text,

[ValidateRange(10,2000)]
[int]
$Width = 100,

[Switch]
$Show,

[string]
$OutPath = "$env:temp\qrcode.png"
)


$payload = "$Text"

New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath
}
55 changes: 55 additions & 0 deletions QRCodeGenerator/2.3/New-PSOneQRCodeTwitter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function New-PSOneQRCodeTwitter
{
<#
.SYNOPSIS
Creates a QR code graphic containing a twitter profile
.DESCRIPTION
Creates a QR code graphic in png format that - when scanned by a smart device - opens the twitter profile.
.PARAMETER ProfileName
The twitter profile name
.PARAMETER Show
Opens the generated QR code in associated program
.PARAMETER OutPath
Path to generated png file. When omitted, a temporary file name is used.
.EXAMPLE
New-PSOneQRCodeTwitter -ProfileName tobiaspsp -Width 200 -Show -OutPath "$home\Desktop\qr.png"
Creates a QR code png graphics on your desktop, and opens it with the associated program
.NOTES
Compatible with all PowerShell versions including PowerShell 6/Core
Uses binaries from https://github.com/codebude/QRCoder/wiki
.LINK
https://github.com/TobiasPSP/Modules.QRCodeGenerator
#>

[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[string]
$ProfileName,

[ValidateRange(10,2000)]
[int]
$Width = 100,

[Switch]
$Show,

[string]
$OutPath = "$env:temp\qrcode.png"
)


$payload = "http://www.twitter.com/$ProfileName"

Write-Verbose "$ProfileName $Width $Show $OutPath $payload"

New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath

}
88 changes: 88 additions & 0 deletions QRCodeGenerator/2.3/New-PSOneQRCodeVCard.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
function New-PSOneQRCodeVCard
{
<#
.SYNOPSIS
Creates a QR code graphic containing person data
.DESCRIPTION
Creates a QR code graphic in png format that - when scanned by a smart device - adds a contact to the address book.
.PARAMETER FirstName
Person first name
.PARAMETER LastName
Person last name
.PARAMETER Company
Company name
.PARAMETER Email
email address
.PARAMETER Width
Height and Width of generated graphics (in pixels). Default is 100.
.PARAMETER Show
Opens the generated QR code in associated program
.PARAMETER OutPath
Path to generated png file. When omitted, a temporary file name is used.
.EXAMPLE
New-PSOneQRCodeVCard -FirstName Tom -LastName Sawyer -Company "Huckle Inc." -Email [email protected] -Width 200 -Show -OutPath "$home\Desktop\qr.png"
Creates a QR code png graphics on your desktop, and opens it with the associated program
.NOTES
Compatible with all PowerShell versions including PowerShell 6/Core
Uses binaries from https://github.com/codebude/QRCoder/wiki
.LINK
https://github.com/TobiasPSP/Modules.QRCodeGenerator
#>


param
(
[Parameter(Mandatory)]
[string]
$FirstName,

[Parameter(Mandatory)]
[string]
$LastName,

[Parameter(Mandatory)]
[string]
$Company,

[Parameter(Mandatory)]
[AllowEmptyString()]
[string]
$Email,

[ValidateRange(10,2000)]
[int]
$Width = 100,

[Switch]
$Show,

[string]
$OutPath = "$env:temp\qrcode.png"
)

$Name = "$FirstName $LastName"

$payload = @"
BEGIN:VCARD
VERSION:3.0
KIND:individual
N:$LastName;$FirstName
FN:$Name
ORG:$Company
EMAIL;TYPE=INTERNET:$Email
END:VCARD
"@

New-PSOneQRCode -payload $payload -Show $Show -Width $Width -OutPath $OutPath
}
Loading

0 comments on commit 03d6468

Please sign in to comment.