aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorpacien2020-02-03 19:00:04 +0100
committerNotkea2020-02-03 19:05:33 +0100
commitbb186990000dd133ecfe6741472b03af92eea233 (patch)
tree51e35e186613010a548e6fbb7dca1c893e1aa765 /compiler
parentc7c872291c2b053afc2c27f999f33b2cfb6c23f1 (diff)
downloadldgallery-bb186990000dd133ecfe6741472b03af92eea233.tar.gz
compiler: handle image resolution parsing error
GitHub: closes #86
Diffstat (limited to 'compiler')
-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