Skip to content

Commit

Permalink
Conversion to binary images using ImageMagick and juicypixels
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhjain committed Apr 19, 2014
0 parents commit 0f996b1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Codec.Picture
import System.Cmd (system)
import System.Environment (getArgs)

toBinaryImage :: Either String DynamicImage -> Image PixelYA8
toBinaryImage = pixelMap (\x -> if x > 128 then PixelYA8 255 100 else PixelYA8 0 100) . extractPixel . extractImage where
extractImage x = let (Right w) = x in w
extractPixel x = let (ImageY8 w) = x in w

main = do
imageName <- getArgs
system $ "convert " ++ head imageName ++ " -resize 600x600 -gravity Center -extent 600x600 -colorspace Gray " ++ "gs_" ++ head imageName -- ImageMagick
gsImage <- readImage $ "gs_" ++ head imageName
system $ "rm " ++ "gs_" ++ head imageName
writePng ("binary" ++ takeWhile (/= '.') (head imageName) ++ ".png") $ toBinaryImage gsImage

0 comments on commit 0f996b1

Please sign in to comment.