Skip to content

Commit

Permalink
Workflow update
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed Aug 7, 2024
1 parent 378ee05 commit d6a2ef3
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions .github/workflows/scripts/generate-qr.csx
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
#!/usr/bin/env dotnet-script

#r "nuget: QRCoder"
#r "nuget: ZXing.Net, 0.16.9"
#r "nuget: ZXing.Net.Bindings.SkiaSharp, 0.16.9"
#r "nuget: SkiaSharp, 2.88.3"

using QRCoder;
using System;
using System.IO;
using ZXing;
using ZXing.QrCode;
using ZXing.SkiaSharp;
using ZXing.SkiaSharp.Rendering;
using SkiaSharp;

if (args.Length != 2)
if (Args.Count != 2)
{
Console.WriteLine("Usage: dotnet-script generate-qr.csx <url> <output-file>");
return;
}

string url = args[0];
string outputFile = args[1];
string url = Args[0];
string outputFile = Args[1];

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q);
PngByteQRCode qrCode = new PngByteQRCode(qrCodeData);
byte[] qrCodeImage = qrCode.GetGraphic(20);
var qrCodeEncodingOptions = new QrCodeEncodingOptions
{
Height = 512,
Width = 512,
Margin = 4
};

var barcodeWriter = new BarcodeWriter<SKBitmap>
{
Format = BarcodeFormat.QR_CODE,
Options = qrCodeEncodingOptions,
Renderer = new SKBitmapRenderer()
};

using (var bitmap = barcodeWriter.Write(url))
{
using (var image = SKImage.FromBitmap(bitmap))
using (var data = image.Encode(SKEncodedImageFormat.Png, 100))
using (var stream = File.OpenWrite(outputFile))
{
data.SaveTo(stream);
}
}

File.WriteAllBytes(outputFile, qrCodeImage);
Console.WriteLine($"QR Code saved to {outputFile}");

0 comments on commit d6a2ef3

Please sign in to comment.