image-type

Determine the type of an image by reading the first bytes.

https://github.com/Icelandjack/Image-type

Latest on Hackage:0.1.0.0@rev:1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD-3-Clause licensed by Baldur Blöndal
Maintained by [email protected]

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.