-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Determine the type of an image by reading the first bytes. -- -- A package used to determine the type of an image according to its -- first bytes based on the Python library imghdr. -- -- Most simplest usage is getting the type of a file: -- --
--   >>> import Codec.ImageType
--   
--   >>> getFileType "/tmp/mystery_file"
--   Just "webp"
--   
-- -- Or to test for a specific extension: -- --
--   >>> isPgm "/tmp/file.pgm"
--   True
--   
--   >>> import qualified Data.ByteString as B
--   
--   >>> testPgm <$> B.readFile "/tmp/file.pgm"
--   Just "pgm"
--   
-- -- Or to filter files by extension: -- --
--   >>> import Codec.ImageType
--   
--   >>> import Control.Monad
--   
--   >>> import System.Directory
--   
--   >>> 
--   
--   >>> getDirectoryContents "." >>= filterM doesFileExist >>= filterM isJpeg
--   ["file2.jpeg","file1.jpeg"]
--   
-- -- Supports the following extensions: JPEG, PNG, -- GIF, TIFF, RGB, PBM, PGM, -- PPM, RAST, XBM, BMP, -- WebP, EXR. @package image-type @version 0.1.0.0 -- | Infers an image's type by looking at its initial values and comparing -- against some magic bytes: -- --
--   >>> :set -XOverloadedStrings
--   
--   >>> import Codec.ImageType
--   
--   >>> import System.IO
--   
--   >>> import qualified Data.ByteString as B
--   
--   >>> 
--   
--   >>> h <- openFile "/tmp/1_webp_ll.webp" ReadMode
--   
--   >>> bytes <- hGet h 32
--   
--   >>> B.isInfixOf "RIFF" bytes
--   True
--   
--   >>> bytes
--   "RIFF\144h\SOH\NULWEBPVP8L\131h\SOH\NUL/\143\SOHK\DLE\141\&8l\219F\146\224"
--   
--   >>> getFileType "/tmp/1_webp_ll.webp"
--   Just "webp"
--   
-- -- Some other examples: -- --
--   >>> import System.Process
--   
--   >>> import System.Directory
--   
--   >>> import Control.Monad
--   
--   >>> let findTiffs = lines <$> readProcess "locate" ["*.tiff"] ""
--   
--   >>> length <$> findTiffs
--   25
--   
--   >>> findTiffs >>= filterM doesFileExist >>= mapM getFileType
--   [Just "tiff",Just "tiff", …
--   
--   >>> sequence_ <$> (findTiffs >>= filterM doesFileExist >>= mapM getFileType)
--   Just ()
--   
module Codec.ImageType -- | Gets a ginel possible file types based on fairly arbitrary tie -- breaking. -- --
--   >>> import System.Directory
--   
--   >>> import Control.Monad
--   
--   >>> getDirectoryContents "." >>= filterM doesFileExist >>= mapM getFileType
--   [Just "rast",Just "jpeg",Nothing,Just "webp",Just "gif",Just "pgm",Just "webp",Nothing,Just "webp",Just "exr"]
--   
getFileType :: FilePath -> IO (Maybe String) -- | Gets possible file types. Returns empty list if nothing is found, -- otherwise a list of matches. -- --
--   >>> import System.Directory
--   
--   >>> import Control.Monad
--   
--   >>> getDirectoryContents "." >>= filterM doesFileExist >>= mapM getFileTypes
--   [["rast"],["jpeg"],[],["webp"],["gif"],["pgm"],["webp"],[],["webp"],["exr"]]
--   
getFileTypes :: FilePath -> IO [String] -- | Checks if file is jpeg. -- --
--   >>> import Codec.ImageType
--   
--   >>> import Control.Monad
--   
--   >>> import System.Directory
--   
--   >>> 
--   
--   >>> 
--   
--   >>> getDirectoryContents "." >>= filterM doesFileExist >>= filterM isJpeg
--   ["file2.jpeg","file1.jpeg"]
--   
isJpeg :: FilePath -> IO Bool -- | Checks if file is png. isPng :: FilePath -> IO Bool -- | Checks if file is gif. isGif :: FilePath -> IO Bool -- | Checks if file is tiff. isTiff :: FilePath -> IO Bool -- | Checks if file is rgb. isRgb :: FilePath -> IO Bool -- | Checks if file is pbm. isPbm :: FilePath -> IO Bool -- | Checks if file is pgm. isPgm :: FilePath -> IO Bool -- | Checks if file is ppm. isPpm :: FilePath -> IO Bool -- | Checks if file is rast. isRast :: FilePath -> IO Bool -- | Checks if file is xbm. isXbm :: FilePath -> IO Bool -- | Checks if file is bmp. isBmp :: FilePath -> IO Bool -- | Checks if file is webp. isWebp :: FilePath -> IO Bool -- | Checks if file is exr. isExr :: FilePath -> IO Bool -- | Joint Photographic Experts Group (JPEG). Returns Just -- jpeg if file satisfies check. testJpeg :: ByteString -> Maybe String -- | Portable Network Graphics (PNG). Returns Just png if -- file satisfies check against magic number 89 50 4e 47 0d 0a 1a -- 0a. testPng :: ByteString -> Maybe String -- | Graphics Interchange Format (GIF). Returns Just gif if -- file satisfies check against magic number GIF87a and -- GIF89a. testGif :: ByteString -> Maybe String -- | Tagged Image File Format (TIFF). Returns Just tiff if -- first short is II or MM. testTiff :: ByteString -> Maybe String -- | SGI image library. Checks magic number (decimal value 474 as a short) -- that identifies file as an SGI image file and then returns Just -- rgb. testRgb :: ByteString -> Maybe String -- | PBM (portable bitmap). Returns Just pbm if file -- satisfies check. testPbm :: ByteString -> Maybe String -- | PGM (portable graymap). Returns Just pgm if file -- satisfies check. testPgm :: ByteString -> Maybe String -- | PPM (portable pixmap). Returns Just ppm if file -- satisfies check. testPpm :: ByteString -> Maybe String -- | Sun raster file. Returns Just rast if file satisfies -- check. testRast :: ByteString -> Maybe String -- | X bitmap (X10 or X11). Returns Just xbm if file -- satisfies check. testXbm :: ByteString -> Maybe String -- | Bitmap (BMP) file format. Returns Just bmp if file -- satisfies check. testBmp :: ByteString -> Maybe String -- | WebP. Returns Just webp if file satisfies check. testWebp :: ByteString -> Maybe String -- | OpenEXR. Returns Just exr if file satisfies check. testExr :: ByteString -> Maybe String