Created
May 18, 2015 09:31
-
-
Save minoki/054265a32884ce7d9e6e to your computer and use it in GitHub Desktop.
An example program using haskell-qrencode library.
This file contains hidden or 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
import qualified Data.QRCode as Q -- from `haskell-qrencode' package | |
import qualified Codec.Picture as P -- from `JuicyPixels' package | |
import qualified Codec.Picture.Png as P | |
import qualified Data.ByteString.Lazy as B | |
pixelPerCell = 5 | |
main :: IO () | |
main = do l <- getLine | |
let version = Nothing -- auto | |
errorLevel = Q.QR_ECLEVEL_M | |
mode = Q.QR_MODE_EIGHT | |
qr <- Q.encodeString l version errorLevel mode True | |
let width = Q.getQRCodeWidth qr | |
mat = Q.toMatrix qr | |
pixelAt x y = let x' = x `div` pixelPerCell | |
y' = y `div` pixelPerCell | |
i = y' | |
j = x' | |
in if mat!!i!!j == 0 then maxBound else minBound :: P.Pixel8 | |
image = P.generateImage pixelAt (width*pixelPerCell) (width*pixelPerCell) | |
encodedImage = P.encodePng image | |
B.writeFile "out.png" encodedImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment