Fixed thumbnail generation for video_port captures
This commit is contained in:
parent
32ec2b463d
commit
1f12154876
3 changed files with 15 additions and 5 deletions
|
|
@ -1,3 +1,3 @@
|
|||
from . import capture, capture_manager
|
||||
from .capture import CaptureObject
|
||||
from .capture import CaptureObject, THUMBNAIL_SIZE
|
||||
from .capture_manager import CaptureManager
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import logging
|
|||
import os
|
||||
import uuid
|
||||
from collections import OrderedDict
|
||||
from PIL import Image
|
||||
|
||||
import dateutil.parser
|
||||
|
||||
|
|
@ -14,6 +15,7 @@ from openflexure_microscope.camera.piexif._exceptions import InvalidImageDataErr
|
|||
from openflexure_microscope.config import JSONEncoder
|
||||
|
||||
EXIF_FORMATS = ["JPG", "JPEG", "TIF", "TIFF"]
|
||||
THUMBNAIL_SIZE = (200, 150)
|
||||
|
||||
|
||||
def pull_usercomment_dict(filepath):
|
||||
|
|
@ -347,8 +349,16 @@ class CaptureObject(object):
|
|||
thumbnail = exif_dict.pop("thumbnail")
|
||||
if thumbnail:
|
||||
return io.BytesIO(thumbnail)
|
||||
# If no thumbnail exists, serve the full image
|
||||
return self.data
|
||||
# If no thumbnail exists, make and save one
|
||||
thumb_bytes = io.BytesIO()
|
||||
thumb_im = Image.open(self.data)
|
||||
thumb_im.thumbnail(THUMBNAIL_SIZE)
|
||||
thumb_im.save(thumb_bytes, "jpeg")
|
||||
thumbnail = thumb_bytes.getvalue()
|
||||
exif_dict["thumbnail"] = thumbnail
|
||||
exif_bytes = piexif.dump(exif_dict)
|
||||
piexif.insert(exif_bytes, self.file)
|
||||
return io.BytesIO(thumbnail)
|
||||
|
||||
def save(self) -> None:
|
||||
"""Write stream to file, and save/update metadata file"""
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import pkg_resources
|
|||
from expiringdict import ExpiringDict
|
||||
|
||||
from openflexure_microscope.camera.mock import MissingCamera
|
||||
from openflexure_microscope.captures import CaptureManager
|
||||
from openflexure_microscope.captures import CaptureManager, THUMBNAIL_SIZE
|
||||
from openflexure_microscope.stage.mock import MissingStage
|
||||
from openflexure_microscope.stage.sanga import SangaDeltaStage, SangaStage
|
||||
|
||||
|
|
@ -387,7 +387,7 @@ class Microscope:
|
|||
# Capture to output object
|
||||
extras = {}
|
||||
if fmt == "jpeg":
|
||||
extras["thumbnail"] = (200, 150, 85)
|
||||
extras["thumbnail"] = (*THUMBNAIL_SIZE, 85)
|
||||
logging.info("Starting microscope capture %s", output.file)
|
||||
self.camera.capture(
|
||||
output,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue