Skip to content

Instantly share code, notes, and snippets.

@satosystems
Last active February 19, 2016 19:33
Show Gist options
  • Save satosystems/94181c14883a215cba01 to your computer and use it in GitHub Desktop.
Save satosystems/94181c14883a215cba01 to your computer and use it in GitHub Desktop.
Haskell でサムネイル #2 ref: http://qiita.com/satosystems/items/669a8b3fdfa535582cb4
$ identify original.jpg
original.jpg JPEG 3264x2448 3264x2448+0+0 8-bit sRGB 3.288MB 0.000u 0:00.000
$ identify -format "%w %h" original.jpg
3264 2448
$ convert -resize 200x150 original.jpg thumb.jpg
$ convert -auto-orient -strip -resize 200x200 original.jpg thumb.jpg
thumb <- mkThumbnail' ((50, 50), (200, 200)) contents
case thumb of
(Left _) -> return Nothing
(Right t) -> return $ Just (fst $ sz t, snd $ sz t)
system $ "convert -auto-orient -strip -resize 200x200 " ++ org ++ " " ++ thumb
wh <- readProcess "identify" ["-format", "%w %h", thumb] []
let a = " " `splitOn` wh
return $ Just (read $ a !! 0, read $ a !! 1)
import Data.Either (either)
import Data.Map.Lazy (fromList)
import Graphics.HsExif (getOrientation, parseFileExif)
file :: FilePath
file = "tools/4f517b31-caea-4ade-9cc5-069d6c9970dd.jpeg"
main :: IO ()
main = do
eexif <- parseFileExif file
let exif = either (\a -> fromList []) id eexif
mio = getOrientation exif
print mio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment