aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Processors.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Processors.hs')
-rw-r--r--compiler/src/Processors.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/compiler/src/Processors.hs b/compiler/src/Processors.hs
index df7e632..fc719af 100644
--- a/compiler/src/Processors.hs
+++ b/compiler/src/Processors.hs
@@ -27,16 +27,17 @@ module Processors
27import Control.Exception (Exception) 27import Control.Exception (Exception)
28import Data.Function ((&)) 28import Data.Function ((&))
29import Data.Char (toLower) 29import Data.Char (toLower)
30import Data.List (break)
30 31
31import System.Directory hiding (copyFile) 32import System.Directory hiding (copyFile)
32import qualified System.Directory 33import qualified System.Directory
33import System.FilePath 34import System.FilePath
34 35
35import System.Process (callProcess) 36import System.Process (callProcess, readProcess)
36 37
37import Resource 38import Resource
38 ( ItemProcessor, ThumbnailProcessor 39 ( ItemProcessor, ThumbnailProcessor
39 , GalleryItemProps(..), Resolution(..), Resource(..) ) 40 , GalleryItemProps(..), Resolution(..), Resource(..), Thumbnail(..) )
40 41
41import Files 42import Files
42 43
@@ -123,6 +124,12 @@ withCached processor inputPath outputPath =
123resourceAt :: FilePath -> Path -> IO Resource 124resourceAt :: FilePath -> Path -> IO Resource
124resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath 125resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath
125 126
127getImageResolution :: FilePath -> IO Resolution
128getImageResolution fsPath =
129 readProcess "identify" ["-format", "%w %h", fsPath] []
130 >>= return . break (== ' ')
131 >>= return . \(w, h) -> Resolution (read w) (read h)
132
126 133
127type ItemFileProcessor = 134type ItemFileProcessor =
128 FileName -- ^ Input base path 135 FileName -- ^ Input base path
@@ -162,12 +169,14 @@ thumbnailFileProcessor maxRes cached inputBase outputBase resClass inputRes =
162 inPath = localPath $ inputBase /> inputRes 169 inPath = localPath $ inputBase /> inputRes
163 outPath = localPath $ outputBase /> relOutPath 170 outPath = localPath $ outputBase /> relOutPath
164 171
165 process :: Maybe FileProcessor -> IO (Maybe Resource) 172 process :: Maybe FileProcessor -> IO (Maybe Thumbnail)
166 process Nothing = return Nothing 173 process Nothing = return Nothing
167 process (Just proc) = 174 process (Just proc) =
168 proc inPath outPath 175 do
169 >> resourceAt outPath relOutPath 176 proc inPath outPath
170 >>= return . Just 177 resource <- resourceAt outPath relOutPath
178 resolution <- getImageResolution outPath
179 return $ Just $ Thumbnail resource resolution
171 180
172 processorFor :: Format -> Maybe FileProcessor 181 processorFor :: Format -> Maybe FileProcessor
173 processorFor PictureFormat = Just $ resizePictureUpTo maxRes 182 processorFor PictureFormat = Just $ resizePictureUpTo maxRes