@@ -138,7 +138,7 @@ imageSize opts img =
138 Just Jpeg -> jpegSize img
138 Just Jpeg -> jpegSize img
139 Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
139 Just Svg -> mbToEither "could not determine SVG size" $ svgSize opts img
140 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
140 Just Eps -> mbToEither "could not determine EPS size" $ epsSize img
141− Just Pdf -> Left "could not determine PDF size" -- TODO
141+ Just Pdf -> mbToEither "Could not determine PDF size" $ pdfSize img
142 Nothing -> Left "could not determine image type"
142 Nothing -> Left "could not determine image type"
143 where mbToEither msg Nothing = Left msg
143 where mbToEither msg Nothing = Left msg
144 mbToEither _ (Just x) = Right x
144 mbToEither _ (Just x) = Right x
@@ -277,6 +277,27 @@ epsSize img = do
277 , dpiY = 72 }
277 , dpiY = 72 }
278 _ -> mzero
278 _ -> mzero
280+pdfSize :: ByteString -> Maybe ImageSize
282+ case dropWhile (\l -> not (l == "stream" ||
283+ "/MediaBox" `B.isPrefixOf` l)) (B.lines img) of
285+ | "/MediaBox" `B.isPrefixOf` x
286+ -> case B.words $ B.filter (\c -> c /= '[' && c /= ']')
288+ [x1, y1, x2, y2] -> do
289+ x1' <- safeRead $ B.unpack x1
290+ x2' <- safeRead $ B.unpack x2
291+ y1' <- safeRead $ B.unpack y1
292+ y2' <- safeRead $ B.unpack y2
280pngSize :: ByteString -> Maybe ImageSize
301pngSize :: ByteString -> Maybe ImageSize
281pngSize img = do
302pngSize img = do
282 let (h, rest) = B.splitAt 8 img
303 let (h, rest) = B.splitAt 8 img