aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/Processors.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs
index 16837a6..6ab4eb5 100644
--- a/compiler/src/Processors.hs
+++ b/compiler/src/Processors.hs
@@ -24,10 +24,11 @@ module Processors
24 ) where 24 ) where
25 25
26 26
27import Control.Exception (Exception) 27import Control.Exception (Exception, throwIO)
28import Data.Function ((&)) 28import Data.Function ((&))
29import Data.Char (toLower) 29import Data.Char (toLower)
30import Data.List (break) 30import Data.List (break)
31import Text.Read (readMaybe)
31 32
32import System.Directory hiding (copyFile) 33import System.Directory hiding (copyFile)
33import qualified System.Directory 34import qualified System.Directory
@@ -126,12 +127,18 @@ resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource res
126 127
127getImageResolution :: FilePath -> IO Resolution 128getImageResolution :: FilePath -> IO Resolution
128getImageResolution fsPath = 129getImageResolution fsPath =
129 readProcess "identify" ["-format", "%w %h", firstFrame] [] 130 readProcess "magick" ["identify", "-format", "%w %h", firstFrame] []
130 >>= return . break (== ' ') 131 >>= parseResolution . break (== ' ')
131 >>= return . \(w, h) -> Resolution (read w) (read h)
132 where 132 where
133 firstFrame :: FilePath
133 firstFrame = fsPath ++ "[0]" 134 firstFrame = fsPath ++ "[0]"
134 135
136 parseResolution :: (String, String) -> IO Resolution
137 parseResolution (widthString, heightString) =
138 case (readMaybe widthString, readMaybe heightString) of
139 (Just w, Just h) -> return $ Resolution w h
140 _ -> throwIO $ ProcessingException fsPath "Unable to read image resolution."
141
135 142
136type ItemFileProcessor = 143type ItemFileProcessor =
137 FileName -- ^ Input base path 144 FileName -- ^ Input base path