hsexif-0.6.0.1: EXIF handling library in pure Haskell

Safe HaskellNone

Graphics.HsExif

Contents

Description

Ability to work with the EXIF data contained in JPEG files.

Synopsis

Documentation

EXIF parsing from JPEG files. EXIF tags are enumerated as ExifTag values, check exposureTime for instance. If you use the predefined ExifTag values, you don't care about details of the ExifTag type, however you should check out the ExifValue type.

Regarding the ExifTag type there is however a field of that type that may interest you: prettyPrinter. It's a function that'll format nicely an exif value for that exif tag as a String. For instance for the flash ExifTag, it'll say whether the flash was fired or not, if there was return light and so on.

Generally speaking, you start from a JPEG file, you can parse its exif tags as a Map of ExifTag to ExifValue using parseExif or parseFileExif. You can enumerate the map or lookup the tags that interest you.

There are also a couple of higher-level helpers like getOrientation, getDateTimeOriginal, wasFlashFired and getGpsLatitudeLongitude.

Main functions

parseFileExif :: FilePath -> IO (Either String (Map ExifTag ExifValue))Source

Read EXIF data from the file you give. It's a key-value map.

parseExif :: ByteString -> Either String (Map ExifTag ExifValue)Source

Read EXIF data from a lazy bytestring.

Higher-level helper functions

readExifDateTime :: String -> Maybe LocalTimeSource

Decode an EXIF date time value. Will return Nothing in case parsing fails.

getDateTimeOriginal :: Map ExifTag ExifValue -> Maybe LocalTimeSource

Extract the date and time when the picture was taken from the EXIF information.

getOrientation :: Map ExifTag ExifValue -> Maybe ImageOrientationSource

Extract the image orientation from the EXIF information. Will return Nothing on parse error.

getGpsLatitudeLongitude :: Map ExifTag ExifValue -> Maybe (Double, Double)Source

Extract the GPS latitude and longitude where the picture was taken (if it is present in the EXIF)

wasFlashFired :: Map ExifTag ExifValue -> Maybe BoolSource

Will return Just True if the flash was fired, Just False if it was not, and Nothing if the file does not contain the information.

formatAsFloatingPoint :: Int -> ExifValue -> StringSource

Format the exif value as floating-point if it makes sense, otherwise use the default show implementation. The first parameter lets you specify how many digits after the comma to format in the result string. The special behaviour applies only for ExifRational and ExifRationalList.

getGpsDateTime :: Map ExifTag ExifValue -> Maybe LocalTimeSource

Extract the GPS date time, if present in the picture.

parseGpsTime :: ExifValue -> Maybe TimeOfDaySource

read the GPS time from the gpsTimeStamp field.

The ExifValue type

data ExifValue Source

An exif value.

If you want a string describing the contents of the value, simply use show.

Constructors

ExifNumber !Int

An exif number. Originally it could have been short, int, signed or not.

ExifText !String

ASCII text.

ExifRational !Int !Int

A rational number (numerator, denominator). Sometimes we're used to it as rational (exposition time: 1/160), sometimes as float (exposure compensation, we rather think -0.75) show will display it as 1/160.

ExifNumberList ![Int]

List of numbers. Originally they could have been short, int, signed or not.

ExifRationalList ![(Int, Int)]

A list of rational numbers (numerator, denominator). Sometimes we're used to it as rational (exposition time: 1/160), sometimes as float (exposure compensation, we rather think -0.75) show will display it as 1/160.

ExifUndefined !ByteString

The undefined type in EXIF means that the contents are not specified and up to the manufacturer. In effect it's exactly a bytestring. Sometimes it's text with ASCII or UNICODE at the beginning, often it's binary in nature.

ExifUnknown !Word16 !Int !Int

Unknown exif value type. All EXIF 2.3 types are supported, it could be a newer file. The parameters are type, count then value

Most useful exif tags

GPS related exif tags

Less useful exif tags

If you need to declare your own exif tags

data ExifTag Source

An exif tag. Normally you don't need to fiddle with this, except maybe if the library doesn't know the particular exif tag you're interested in. Rather check the list of supported exif tags, like exposureTime and so on.

Constructors

ExifTag 

Fields

tagLocation :: TagLocation

In which part of the JPEG file the exif tag was found

tagDesc :: Maybe String

Description of the exif tag (exposureTime, fnumber...) or if unknown, Nothing. This should be purely for debugging purposes, to compare tags use == on ExifTag or compare the tagKey.

tagKey :: Word16

Exif tag key, the number uniquely identifying this tag.

prettyPrinter :: ExifValue -> Text

A function that'll display nicely an exif value for that exif tag. For instance for the flash ExifTag, it'll say whether the flash was fired or not, if there was return light and so on.

data TagLocation Source

Location of the tag in the JPG file structure. Normally you don't need to fiddle with this, except maybe if the library doesn't know the particular exif tag you're interested in. Rather check the list of supported exif tags, like exposureTime and so on.

Constructors

ExifSubIFD 
IFD0 
GpsSubIFD