From 10d264c526aaaaffcaf0884cd99a68a5f3e8de02 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 27 Oct 2020 14:05:24 +0000 Subject: [PATCH] Always use builtin JPEG thumbnails --- openflexure_microscope/captures/capture.py | 25 ++++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/openflexure_microscope/captures/capture.py b/openflexure_microscope/captures/capture.py index 2c2812f5..2550c59d 100644 --- a/openflexure_microscope/captures/capture.py +++ b/openflexure_microscope/captures/capture.py @@ -16,7 +16,6 @@ from openflexure_microscope.config import JSONEncoder PIL_FORMATS = ["JPG", "JPEG", "PNG", "TIF", "TIFF"] EXIF_FORMATS = ["JPG", "JPEG", "TIF", "TIFF"] -THUMBNAIL_SIZE = (200, 150) def pull_usercomment_dict(filepath): @@ -145,9 +144,6 @@ class CaptureObject(object): # List for storing tags self.tags = [] - # Thumbnail (populated only for PIL captures) - self.thumb_bytes = None - def write(self, s): logging.debug("Writing to %s", self) self.stream.write(s) @@ -349,21 +345,12 @@ class CaptureObject(object): """ Returns a thumbnail of the capture data, for supported image formats. """ - # If no thumbnail exists, try and make one - if not self.thumb_bytes: - logging.info("Building thumbnail") - self.thumb_bytes = io.BytesIO() - if self.format.upper() in PIL_FORMATS: - im = Image.open(self.data) - im.thumbnail(THUMBNAIL_SIZE) - im.save(self.thumb_bytes, self.format) - self.thumb_bytes.seek(0) - else: - self.thumb_bytes.seek(0) - - # Copy the buffer, to avoid closing the file - data = io.BytesIO(self.thumb_bytes.getbuffer()) - return data + exif_dict = piexif.load(self.file) + thumbnail = exif_dict.pop("thumbnail") + if thumbnail: + return io.BytesIO(thumbnail) + # If no thumbnail exists, serve the full image + return self.data.getvalue() def save(self) -> None: """Write stream to file, and save/update metadata file"""