Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ocrd/ocrd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def image_from_segment(self, segment, parent_image, parent_coords,
def save_image_file(self, image,
file_id,
file_grp,
dpi=None,
page_id=None,
mimetype='image/png',
force=False):
Expand All @@ -851,7 +852,15 @@ def save_image_file(self, image,
if not force and self.overwrite_mode:
force = True
image_bytes = io.BytesIO()
image.save(image_bytes, format=MIME_TO_PIL[mimetype])
if dpi and not isinstance(dpi, tuple):
dpi = (dpi, dpi)
elif not dpi:
# TODO - brittle, will this always find the original image?
orig_img_file = self.mets.find_files(pageId=page_id, mimetype='//^image')[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must adapt for the generator now, I believe.

Suggested change
orig_img_file = self.mets.find_files(pageId=page_id, mimetype='//^image')[0]
orig_img_file = next(self.mets.find_files(pageId=page_id, mimetype='//^image', local_only=True))

orig_img_pil = self.resolve_image_exif(orig_img_file.url)
exif = OcrdExif(orig_img_pil)
dpi = (exif.xResolution, exif.yResolution)
image.save(image_bytes, dpi=dpi, format=MIME_TO_PIL[mimetype])
file_path = str(Path(file_grp, '%s%s' % (file_id, MIME_TO_EXT[mimetype])))
out = self.add_file(
ID=file_id,
Expand Down