aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Processors.hs
diff options
context:
space:
mode:
authorpacien2020-01-31 19:43:24 +0100
committerpacien2020-01-31 19:43:24 +0100
commit7dde692101a7e36e0a431aeb864cbf3a0c0e96f8 (patch)
treec16d53fb67ecad8693b219662a18b67852a19ed2 /compiler/src/Processors.hs
parent245fee3fe5abdc6ad14513ef6522446aba4c905a (diff)
downloadldgallery-7dde692101a7e36e0a431aeb864cbf3a0c0e96f8.tar.gz
compiler: add thumbnail size to index
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 f2ade63..9ddc6ee 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
@@ -119,6 +120,12 @@ withCached processor inputPath outputPath =
119resourceAt :: FilePath -> Path -> IO Resource 120resourceAt :: FilePath -> Path -> IO Resource
120resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath 121resourceAt fsPath resPath = getModificationTime fsPath >>= return . Resource resPath
121 122
123getImageResolution :: FilePath -> IO Resolution
124getImageResolution fsPath =
125 readProcess "identify" ["-format", "%w %h", fsPath] []
126 >>= return . break (== ' ')
127 >>= return . \(w, h) -> Resolution (read w) (read h)
128
122 129
123type ItemFileProcessor = 130type ItemFileProcessor =
124 FileName -- ^ Input base path 131 FileName -- ^ Input base path
@@ -158,12 +165,14 @@ thumbnailFileProcessor maxRes cached inputBase outputBase resClass inputRes =
158 inPath = localPath $ inputBase /> inputRes 165 inPath = localPath $ inputBase /> inputRes
159 outPath = localPath $ outputBase /> relOutPath 166 outPath = localPath $ outputBase /> relOutPath
160 167
161 process :: Maybe FileProcessor -> IO (Maybe Resource) 168 process :: Maybe FileProcessor -> IO (Maybe Thumbnail)
162 process Nothing = return Nothing 169 process Nothing = return Nothing
163 process (Just proc) = 170 process (Just proc) =
164 proc inPath outPath 171 do
165 >> resourceAt outPath relOutPath 172 proc inPath outPath
166 >>= return . Just 173 resource <- resourceAt outPath relOutPath
174 resolution <- getImageResolution outPath
175 return $ Just $ Thumbnail resource resolution
167 176
168 processorFor :: Format -> Maybe FileProcessor 177 processorFor :: Format -> Maybe FileProcessor
169 processorFor PictureFormat = Just $ resizePictureUpTo maxRes 178 processorFor PictureFormat = Just $ resizePictureUpTo maxRes