Always use builtin JPEG thumbnails
This commit is contained in:
parent
09849ce064
commit
10d264c526
1 changed files with 6 additions and 19 deletions
|
|
@ -16,7 +16,6 @@ from openflexure_microscope.config import JSONEncoder
|
||||||
|
|
||||||
PIL_FORMATS = ["JPG", "JPEG", "PNG", "TIF", "TIFF"]
|
PIL_FORMATS = ["JPG", "JPEG", "PNG", "TIF", "TIFF"]
|
||||||
EXIF_FORMATS = ["JPG", "JPEG", "TIF", "TIFF"]
|
EXIF_FORMATS = ["JPG", "JPEG", "TIF", "TIFF"]
|
||||||
THUMBNAIL_SIZE = (200, 150)
|
|
||||||
|
|
||||||
|
|
||||||
def pull_usercomment_dict(filepath):
|
def pull_usercomment_dict(filepath):
|
||||||
|
|
@ -145,9 +144,6 @@ class CaptureObject(object):
|
||||||
# List for storing tags
|
# List for storing tags
|
||||||
self.tags = []
|
self.tags = []
|
||||||
|
|
||||||
# Thumbnail (populated only for PIL captures)
|
|
||||||
self.thumb_bytes = None
|
|
||||||
|
|
||||||
def write(self, s):
|
def write(self, s):
|
||||||
logging.debug("Writing to %s", self)
|
logging.debug("Writing to %s", self)
|
||||||
self.stream.write(s)
|
self.stream.write(s)
|
||||||
|
|
@ -349,21 +345,12 @@ class CaptureObject(object):
|
||||||
"""
|
"""
|
||||||
Returns a thumbnail of the capture data, for supported image formats.
|
Returns a thumbnail of the capture data, for supported image formats.
|
||||||
"""
|
"""
|
||||||
# If no thumbnail exists, try and make one
|
exif_dict = piexif.load(self.file)
|
||||||
if not self.thumb_bytes:
|
thumbnail = exif_dict.pop("thumbnail")
|
||||||
logging.info("Building thumbnail")
|
if thumbnail:
|
||||||
self.thumb_bytes = io.BytesIO()
|
return io.BytesIO(thumbnail)
|
||||||
if self.format.upper() in PIL_FORMATS:
|
# If no thumbnail exists, serve the full image
|
||||||
im = Image.open(self.data)
|
return self.data.getvalue()
|
||||||
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
|
|
||||||
|
|
||||||
def save(self) -> None:
|
def save(self) -> None:
|
||||||
"""Write stream to file, and save/update metadata file"""
|
"""Write stream to file, and save/update metadata file"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue