Last active
October 6, 2017 14:16
-
-
Save banjun/67af448a66d2e34ce6098a826a249286 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// % 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