diff options
Diffstat (limited to 'compiler/src/Processors.hs')
-rw-r--r-- | compiler/src/Processors.hs | 21 |
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 | |||
27 | import Control.Exception (Exception) | 27 | import Control.Exception (Exception) |
28 | import Data.Function ((&)) | 28 | import Data.Function ((&)) |
29 | import Data.Char (toLower) | 29 | import Data.Char (toLower) |
30 | import Data.List (break) | ||
30 | 31 | ||
31 | import System.Directory hiding (copyFile) | 32 | import System.Directory hiding (copyFile) |
32 | import qualified System.Directory | 33 | import qualified System.Directory |
33 | import System.FilePath | 34 | import System.FilePath |
34 | 35 | ||
35 | import System.Process (callProcess) | 36 | import System.Process (callProcess, readProcess) |
36 | 37 | ||
37 | import Resource | 38 | import Resource |
38 | ( ItemProcessor, ThumbnailProcessor | 39 | ( ItemProcessor, ThumbnailProcessor |
39 | , GalleryItemProps(..), Resolution(..), Resource(..) ) | 40 | , GalleryItemProps(..), Resolution(..), Resource(..), Thumbnail(..) ) |
40 | 41 | ||
41 | import Files | 42 | import Files |
42 | 43 | ||
@@ -123,6 +124,12 @@ withCached processor inputPath outputPath = | |||
123 | resourceAt :: FilePath -> Path -> IO Resource | 124 | resourceAt :: FilePath -> Path -> IO Resource |
124 | resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath | 125 | resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath |
125 | 126 | ||
127 | getImageResolution :: FilePath -> IO Resolution | ||
128 | getImageResolution fsPath = | ||
129 | readProcess "identify" ["-format", "%w %h", fsPath] [] | ||
130 | >>= return . break (== ' ') | ||
131 | >>= return . \(w, h) -> Resolution (read w) (read h) | ||
132 | |||
126 | 133 | ||
127 | type ItemFileProcessor = | 134 | type 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 |