core
core copied to clipboard
refactor AlternativeImage selection logic out of Workspace into a stateless function (without downloading)
we need to know whether refactoring the AlternativeImage selection logic out of
Workspace.image_from_*into a stateless function (without anydownload_filebehaviour) would break any existing API in the future, hence whether it must be done prior to 3.0 or can be done later.
@kba I don't think we need to break anything here in the future. The methods Workspace.image_from_page and Workspace.image_from_segment could be re-implemented as follows:
- delegate to new generateds user methods
PageType.get_imageand[*Region|TextLine|Word]Type.get_image,
but pass as new kwargresolvea function with the following definition:def resolve(image_url): try: f = next(self.mets.find_files(local_filename=str(image_url))) return f.local_filename except StopIteration: try: f = next(self.mets.find_files(url=str(image_url))) return self.download_file(f).local_filename except StopIteration: with download_temporary_file(image_url) as f: return f.name - replace calls to
resolve_image_exifby calls toexif_from_filenamedirectly,
but allow overriding filename viaresolve - replace calls to
resolve_image_as_pilby calls to a new functionimage_from_filename, which merely contains the parts that doImage.open()and.load()to give up the FD, as well as array conversion for the badly supported color modes I and F, but allow overriding filename viaresolve
Originally posted by @bertsky in https://github.com/bertsky/core/issues/21#issuecomment-2593375060
related: https://github.com/OCR-D/core/issues/264