Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I rotate a JPEG image by 45° and save it back to disk in Haskell?

How do I rotate a JPEG image by 45° and save it back to disk?

like image 222
Jonathan Allen Avatar asked Aug 05 '10 09:08

Jonathan Allen


1 Answers

As far as I know, there is no good image manipulation library for Haskell yet.

Better way

You can use hsmagick (bindings to libmagick) to manipulate images.

See TomMD's answer for an example.

Easy way

But if you want to do it from Haskell, this can do the trick (assuming that ImageMagick is available):

import System.Cmd (system)
import System.Environment (getArgs)

main = do
  (original:rotated:_) <- getArgs
  system $ "convert -rotate \"-45\" \"" ++ original ++ "\" \"" ++ rotated ++ "\""

Usage:

runghc rotate.hs original.jpg rotated45.jpg

Hard way

Or you can choose the hard way, and implement rotation algorithm yourself. To read and write almost all image formats in Haskell, you can use Codec.Image.DevIL library. If you do it, it would be kind of you to put this code on Hackage.

like image 160
sastanin Avatar answered Nov 15 '22 10:11

sastanin