@@ -71,7 +71,7 @@ import Data.Maybe (fromMaybe)
71-- quick and dirty functions to get image sizes
71-- quick and dirty functions to get image sizes
72-- algorithms borrowed from wwwis.pl
72-- algorithms borrowed from wwwis.pl
74−data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps deriving Show
74+data ImageType = Png | Gif | Jpeg | Svg | Pdf | Eps | Emf deriving Show
75data Direction = Width | Height
75data Direction = Width | Height
76instance Show Direction where
76instance Show Direction where
77 show Width = "width"
77 show Width = "width"
@@ -125,6 +125,9 @@ imageType img = case B.take 4 img of
126 | B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
126 | B.take 4 (B.drop 1 $ B.dropWhile (/=' ') img) == "EPSF"
127 -> return Eps
127 -> return Eps
129+ | B.take 4 (B.drop 40 img) == " EMF"
128 _ -> mzero
131 _ -> mzero
130findSvgTag :: ByteString -> Bool
133findSvgTag :: ByteString -> Bool
@@ -139,6 +142,7 @@ imageSize opts img =
139 Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
142 Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
140 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
143 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
141 Just Pdf -> mbToEither "could not determine PDF size" $ pdfSize img
144 Just Pdf -> mbToEither "could not determine PDF size" $ pdfSize img
145+ Just Emf -> mbToEither "could not determine EMF size" $ emfSize img
142 Nothing -> Left "could not determine image type"
146 Nothing -> Left "could not determine image type"
143 where mbToEither msg Nothing = Left msg
147 where mbToEither msg Nothing = Left msg
144 mbToEither _ (Just x) = Right x
148 mbToEither _ (Just x) = Right x
@@ -357,6 +361,38 @@ svgSize opts img = do
357 , dpiX = dpi
361 , dpiX = dpi
358 , dpiY = dpi
362 , dpiY = dpi
365+emfSize :: ByteString -> Maybe ImageSize
368+ parseheader = runGetOrFail $ do
370+ frameL <- getWord32le -- 0x18 measured in 1/100 of a millimetre
371+ frameT <- getWord32le -- 0x1C
372+ frameR <- getWord32le -- 0x20
373+ frameB <- getWord32le -- 0x24
375+ deviceX <- getWord32le -- 0x48 pixels of reference device
376+ deviceY <- getWord32le -- 0x4C
377+ mmX <- getWord32le -- 0x50 real mm of reference device (always 320*240?)
378+ mmY <- getWord32le -- 0x58
381+ w = (deviceX * (frameR - frameL)) `quot` (mmX * 100)
382+ h = (deviceY * (frameB - frameT)) `quot` (mmY * 100)
383+ dpiW = (deviceX * 254) `quot` (mmX * 10)
384+ dpiH = (deviceY * 254) `quot` (mmY * 10)
386+ { pxX = fromIntegral w
387+ , pxY = fromIntegral h
388+ , dpiX = fromIntegral dpiW
389+ , dpiY = fromIntegral dpiH
392+ case parseheader . BL.fromStrict $ img of
394+ Right (_, _, size) -> Just size
361jpegSize :: ByteString -> Either String ImageSize
397jpegSize :: ByteString -> Either String ImageSize
362jpegSize img =
398jpegSize img =