ImageSize: Add Tiff constructor for ImageType.

[Minor API change]

This allows pandoc to get size information from tiff images.
Closes #7405.
This commit is contained in:
John MacFarlane 2021-06-23 11:39:50 -07:00
parent 235cdea629
commit 4a7a0cff29
3 changed files with 7 additions and 1 deletions

View file

@ -57,7 +57,8 @@ import Codec.Picture (decodeImageWithMetadata)
-- quick and dirty functions to get image sizes
-- algorithms borrowed from wwwis.pl
data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps | Emf deriving Show
data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps | Emf | Tiff
deriving Show
data Direction = Width | Height
instance Show Direction where
show Width = "width"
@ -100,6 +101,8 @@ imageType :: ByteString -> Maybe ImageType
imageType img = case B.take 4 img of
"\x89\x50\x4e\x47" -> return Png
"\x47\x49\x46\x38" -> return Gif
"\x49\x49\x2a\x00" -> return Tiff
"\x4D\x4D\x00\x2a" -> return Tiff
"\xff\xd8\xff\xe0" -> return Jpeg -- JFIF
"\xff\xd8\xff\xe1" -> return Jpeg -- Exif
"%PDF" -> return Pdf
@ -124,6 +127,7 @@ imageSize opts img = checkDpi <$>
Just Png -> getSize img
Just Gif -> getSize img
Just Jpeg -> getSize img
Just Tiff -> getSize img
Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
Just Pdf -> mbToEither "could not determine PDF size" $ pdfSize img

View file

@ -1289,6 +1289,7 @@ inlineToOpenXML' opts (Image attr@(imgident, _, _) alt (src, title)) = do
Just Eps -> ".eps"
Just Svg -> ".svg"
Just Emf -> ".emf"
Just Tiff -> ".tiff"
Nothing -> ""
imgpath = "media/" <> ident <> imgext
mbMimeType = mt <|> getMimeType (T.unpack imgpath)

View file

@ -537,6 +537,7 @@ registerMedia fp caption = do
Just Eps -> Just ".eps"
Just Svg -> Just ".svg"
Just Emf -> Just ".emf"
Just Tiff -> Just ".tiff"
Nothing -> Nothing
let newGlobalId = fromMaybe (maxGlobalId + 1) (M.lookup fp globalIds)