How do I rotate a JPEG image by 45° and save it back to disk?
As far as I know, there is no good image manipulation library for Haskell yet.
You can use hsmagick
(bindings to libmagick) to manipulate images.
See TomMD's answer for an example.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With