Skip to content

Instantly share code, notes, and snippets.

@banjun
Last active October 6, 2017 14:16
Show Gist options
  • Save banjun/67af448a66d2e34ce6098a826a249286 to your computer and use it in GitHub Desktop.
Save banjun/67af448a66d2e34ce6098a826a249286 to your computer and use it in GitHub Desktop.
// % swift qrcli.swift TEST > qrcode.png
// or, % swift build -Xswiftc -framework -Xswiftc CoreImage
import CoreImage
import class AppKit.NSBitmapImageRep
func qrcode(_ text: String) -> CIImage {
let filter = CIFilter(name: "CIQRCodeGenerator")!
filter.setValue(text.data(using: .shiftJIS), forKey: "inputMessage")
filter.setValue("M", forKey: "inputCorrectionLevel")
return filter.outputImage!
}
extension CIImage {
var png: Data {
return NSBitmapImageRep(ciImage: self).representation(using: .png, properties: [:])!
}
}
let text = CommandLine.arguments[1]
let png = qrcode(text).png
FileHandle.standardOutput.write(png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment