Advertisement
markopolo2013

Untitled

Jan 4th, 2023
1,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # There will be an error messages when running this in VSCode, but all the code below will still work fine.
  2. # There will be no errors when this script is running directly in ISE or in a PowerShell console instead of VSCode.
  3. Import-Module -Name "$PSScriptRoot\modules\ImagePlayground" -Verbose
  4. $error.Exception.LoaderExceptions
  5.  
  6. # Save QR code to a PNG file
  7. New-ImageQRCode -Content 'Test123_Test123_Test123_Test123_Test123_Test123' -FilePath "$PSScriptRoot\QRCode.png" -Verbose
  8. #$Message = Get-ImageQRCode -FilePath "$PSScriptRoot\QRCode.png"
  9.  
  10. # Crop saved QR code image
  11. # The size of a module is 20 pixels, the tool creates a Quiet Zone of 4x20 pixels. Here we limit the Quiet Zone to 2 modules (40 pixels)
  12. $Image = Get-Image -FilePath "$PSScriptRoot\QRCode.png"
  13. Write-Host "Resolution old: $($Image.Width)x$($Image.Width)"
  14. $Rectangle = [SixLabors.ImageSharp.Rectangle]::new(40, 40, $Image.Width - 80, $Image.Height - 80)
  15. $Image.Crop($Rectangle)
  16. Write-Host "Resolution new: $($Image.Width)x$($Image.Width)"
  17. Save-Image -Image $Image -FilePath "$PSScriptRoot\QRCode_cropped.png"
  18.  
  19. # Resize QR code image to 200%
  20. Write-Host "Resolution old: $($Image.Width)x$($Image.Width)"
  21. $Image.Resize(200)
  22. Write-Host "Resolution new: $($Image.Width)x$($Image.Width)"
  23. Save-Image -Image $Image -FilePath "$PSScriptRoot\QRCode_cropped_resized.png"
  24.  
  25. # Remove color halftones that have been introduced during resizing
  26. #$Image.BlackWhite() # BlackWhite() reduces to 4 instead of 2 unique colors
  27. $Image.Contrast(100)
  28. Save-Image -Image $Image -FilePath "$PSScriptRoot\QRCode_cropped_resized_blackwhite.png"
  29.  
  30. #Pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement