Created
May 18, 2015 09:18
-
-
Save minoki/7d6a610fe03fd84122d5 to your computer and use it in GitHub Desktop.
An example program using haskell-qrcode 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 Codec.Binary.QRCode as Q -- from `qrcode' package | |
import qualified Codec.Picture as P -- from `JuicyPixel' package | |
import qualified Codec.Picture.Png as P | |
import qualified Data.ByteString.Lazy as B | |
import Data.Array (Array,bounds,(!)) | |
pixelPerCell = 5 | |
main :: IO () | |
main = do l <- getLine | |
let Just version = Q.version 1 | |
errorLevel = Q.L -- or Q.M, Q.Q, Q.H | |
mode = Q.Alphanumeric -- or Q.Numeric | |
array :: Array (Int,Int) P.Pixel8 | |
Just array = fmap Q.toArray (Q.encode version errorLevel mode l) | |
((y0,x0),(y1,x1)) = bounds array | |
pixelAt x y = let x' = x `div` pixelPerCell | |
y' = y `div` pixelPerCell | |
i = y'+y0 | |
j = x'+x0 | |
in array!(i,j) | |
image = P.generateImage pixelAt ((x1-x0+1)*pixelPerCell) ((y1-y0+1)*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