diff options
author | pacien | 2020-02-03 19:00:04 +0100 |
---|---|---|
committer | Notkea | 2020-02-03 19:05:33 +0100 |
commit | bb186990000dd133ecfe6741472b03af92eea233 (patch) | |
tree | 51e35e186613010a548e6fbb7dca1c893e1aa765 /compiler/src | |
parent | c7c872291c2b053afc2c27f999f33b2cfb6c23f1 (diff) | |
download | ldgallery-bb186990000dd133ecfe6741472b03af92eea233.tar.gz |
compiler: handle image resolution parsing error
GitHub: closes #86
Diffstat (limited to 'compiler/src')
-rw-r--r-- | compiler/src/Processors.hs | 15 |
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 | ||
27 | import Control.Exception (Exception) | 27 | import Control.Exception (Exception, throwIO) |
28 | import Data.Function ((&)) | 28 | import Data.Function ((&)) |
29 | import Data.Char (toLower) | 29 | import Data.Char (toLower) |
30 | import Data.List (break) | 30 | import Data.List (break) |
31 | import Text.Read (readMaybe) | ||
31 | 32 | ||
32 | import System.Directory hiding (copyFile) | 33 | import System.Directory hiding (copyFile) |
33 | import qualified System.Directory | 34 | import qualified System.Directory |
@@ -126,12 +127,18 @@ resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource res | |||
126 | 127 | ||
127 | getImageResolution :: FilePath -> IO Resolution | 128 | getImageResolution :: FilePath -> IO Resolution |
128 | getImageResolution fsPath = | 129 | getImageResolution 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 | ||
136 | type ItemFileProcessor = | 143 | type ItemFileProcessor = |
137 | FileName -- ^ Input base path | 144 | FileName -- ^ Input base path |