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

Latest on Hackage:

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 to host generated Haddocks.

BSD3 licensed by Baldur Blöndal
Maintained by

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"
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

Supports the following extensions: JPEG, PNG, GIF, TIFF, RGB, PBM, PGM, PPM, RAST, XBM, BMP, WebP, EXR.

Depends on:
Used by 2 packages:
comments powered byDisqus