git.iko.soy/typeable/pandoc
on master help sign in
ImageSize: default to DPI 72 if the format specifies DPI of 0.
2f11026John MacFarlane
src/Text/Pandoc/ImageSize.hs+7−1
@@ -120,7 +120,7 @@ findSvgTag :: ByteString -> Bool
120findSvgTag img = "<svg" `B.isInfixOf` img || "<SVG" `B.isInfixOf` img
120findSvgTag img = "<svg" `B.isInfixOf` img || "<SVG" `B.isInfixOf` img
121
121
122imageSize :: WriterOptions -> ByteString -> Either T.Text ImageSize
122imageSize :: WriterOptions -> ByteString -> Either T.Text ImageSize
123−imageSize opts img =
123+imageSize opts img = checkDpi <$>
124 case imageType img of
124 case imageType img of
125 Just Png -> mbToEither "could not determine PNG size" $ pngSize img
125 Just Png -> mbToEither "could not determine PNG size" $ pngSize img
126 Just Gif -> mbToEither "could not determine GIF size" $ gifSize img
126 Just Gif -> mbToEither "could not determine GIF size" $ gifSize img
@@ -132,6 +132,12 @@ imageSize opts img =
132 Nothing -> Left "could not determine image type"
132 Nothing -> Left "could not determine image type"
133 where mbToEither msg Nothing = Left msg
133 where mbToEither msg Nothing = Left msg
134 mbToEither _ (Just x) = Right x
134 mbToEither _ (Just x) = Right x
135+ -- see #6880, some defective JPEGs may encode dpi 0, so default to 72
136+ -- if that value is 0
137+ checkDpi size =
138+ size{ dpiX = if dpiX size == 0 then 72 else dpiX size
139+ , dpiY = if dpiY size == 0 then 72 else dpiY size }
140+
135
141
136defaultSize :: (Integer, Integer)
142defaultSize :: (Integer, Integer)
137defaultSize = (72, 72)
143defaultSize = (72, 72)