git.iko.soy/typeable/pandoc
on master help sign in
ImageSize: Use default instead of failing if image size not found

in exif header. Closes #1358.

commit2eadc7805392c165f7286bd9a337b310b41c897d authorJohn MacFarlane <jgm@berkeley.edu> dateFri 20 Jun 2014, 10:58 (12 years ago) parentb3b4054
1 file changed+6−1
src/Text/Pandoc/ImageSize.hs+6−1
src/Text/Pandoc/ImageSize.hs+6−1
@@ -76,6 +76,9 @@ imageSize img = do
7676 Eps -> epsSize img
7777 Pdf -> Nothing -- TODO
7878
79+defaultSize :: (Integer, Integer)
80+defaultSize = (72, 72)
81+
7982sizeInPixels :: ImageSize -> (Integer, Integer)
8083sizeInPixels s = (pxX s, pxY s)
8184
@@ -260,7 +263,9 @@ exifHeader hdr = do
260263 lookup ExifImageHeight allentries) of
261264 (Just (UnsignedLong w), Just (UnsignedLong h)) ->
262265 return (fromIntegral w, fromIntegral h)
263− _ -> fail "Could not determine image width, height"
266+ _ -> return defaultSize
267+ -- we return a default width and height when
268+ -- the exif header doesn't contain these
264269 let resfactor = case lookup ResolutionUnit allentries of
265270 Just (UnsignedShort 1) -> (100 / 254)
266271 _ -> 1