From bb186990000dd133ecfe6741472b03af92eea233 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 3 Feb 2020 19:00:04 +0100 Subject: compiler: handle image resolution parsing error GitHub: closes #86 --- compiler/src/Processors.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'compiler') 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 ) where -import Control.Exception (Exception) +import Control.Exception (Exception, throwIO) import Data.Function ((&)) import Data.Char (toLower) import Data.List (break) +import Text.Read (readMaybe) import System.Directory hiding (copyFile) import qualified System.Directory @@ -126,12 +127,18 @@ resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource res getImageResolution :: FilePath -> IO Resolution getImageResolution fsPath = - readProcess "identify" ["-format", "%w %h", firstFrame] [] - >>= return . break (== ' ') - >>= return . \(w, h) -> Resolution (read w) (read h) + readProcess "magick" ["identify", "-format", "%w %h", firstFrame] [] + >>= parseResolution . break (== ' ') where + firstFrame :: FilePath firstFrame = fsPath ++ "[0]" + parseResolution :: (String, String) -> IO Resolution + parseResolution (widthString, heightString) = + case (readMaybe widthString, readMaybe heightString) of + (Just w, Just h) -> return $ Resolution w h + _ -> throwIO $ ProcessingException fsPath "Unable to read image resolution." + type ItemFileProcessor = FileName -- ^ Input base path -- cgit v1.2.3