blob: e46ae042e1132ba2ce379d1b76e1dd5eb0985251 (
plain) (
tree)
|
|
From b3324c3b4e8052176f5ec86eda1ea726894fd510 Mon Sep 17 00:00:00 2001
From: "James R. Barlow" <james@purplerock.ca>
Date: Sat, 31 Aug 2024 00:37:52 -0700
Subject: [PATCH] Don't assume /Mask is always a Stream
Fixes #1377
---
src/ocrmypdf/pdfinfo/info.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/ocrmypdf/pdfinfo/info.py b/src/ocrmypdf/pdfinfo/info.py
index 7c946906b..953af9cd5 100644
--- a/src/ocrmypdf/pdfinfo/info.py
+++ b/src/ocrmypdf/pdfinfo/info.py
@@ -382,8 +382,12 @@ def __init__(
self._height = max(smask.get(Name.Height, 0), self._height)
if (mask := pim.obj.get(Name.Mask, None)) is not None:
# If the image has a /Mask entry, it has an explicit mask.
- self._width = max(mask.get(Name.Width, 0), self._width)
- self._height = max(mask.get(Name.Height, 0), self._height)
+ # /Mask can be a Stream or an Array. If it's a Stream,
+ # use its /Width and /Height if they are larger than the main
+ # image's.
+ if isinstance(mask, Stream):
+ self._width = max(mask.get(Name.Width, 0), self._width)
+ self._height = max(mask.get(Name.Height, 0), self._height)
# If /ImageMask is true, then this image is a stencil mask
# (Images that draw with this stencil mask will have a reference to
|