From acad220a119da9fc0ca4c77a6e275be9510178a7 Mon Sep 17 00:00:00 2001 From: Benjamin Braatz Date: Wed, 4 Aug 2021 11:12:23 +0200 Subject: [PATCH] Remove thumbnail image, web image for each full image. --- controlpi_plugins/camera.py | 55 ++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/controlpi_plugins/camera.py b/controlpi_plugins/camera.py index 065f6f1..26ada04 100644 --- a/controlpi_plugins/camera.py +++ b/controlpi_plugins/camera.py @@ -23,17 +23,15 @@ class Camera(BasePlugin): 'full': {'type': 'array', 'items': {'type': 'integer'}, 'minItems': 2, 'maxItems': 2}, 'web': {'type': 'array', 'items': {'type': 'integer'}, - 'minItems': 2, 'maxItems': 2}, - 'thumb': {'type': 'array', 'items': {'type': 'integer'}, - 'minItems': 2, 'maxItems': 2}}, + 'minItems': 2, 'maxItems': 2}}, 'required': ['pause', 'keep', 'path']} async def _receive(self, message: Message) -> None: if message['command'] == 'get image': if len(self._images) > 0: await self.bus.send(Message(self.name, - {'image': self._images[0][0], - 'date': self._images[0][1]})) + {'image': self._images[-1][0], + 'date': self._images[-1][1]})) elif message['command'] == 'start capture': self._capture = True elif message['command'] == 'stop capture': @@ -52,9 +50,6 @@ class Camera(BasePlugin): self._web = (640, 480) if 'web' in self.conf: self._web = self.conf['web'] - self._thumb = (160, 120) - if 'thumb' in self.conf: - self._thumb = self.conf['thumb'] sends = [MessageTemplate({'event': {'const': 'new image'}, 'image': {'type': 'string'}, 'date': {'type': 'string'}}), @@ -75,8 +70,6 @@ class Camera(BasePlugin): camera = picamera.PiCamera() camera.iso = self._iso camera.resolution = self._full - web_path = os.path.join(self.conf['path'], 'web.jpg') - thumb_path = os.path.join(self.conf['path'], 'thumb.jpg') try: while True: if self._capture: @@ -92,14 +85,22 @@ class Camera(BasePlugin): camera.awb_gains = gains while self._capture: while len(self._images) >= self.conf['keep']: - file_name = self._images.popleft()[0] - file_path = os.path.join(self.conf['path'], - file_name) - await aiofiles.os.remove(file_path) + full_name = self._images.popleft()[0] + full_path = os.path.join(self.conf['path'], + full_name) + if os.path.isfile(full_path): + await aiofiles.os.remove(full_path) + web_name = 'web-'+full_name + web_path = os.path.join(self.conf['path'], + web_name) + if os.path.isfile(web_path): + await aiofiles.os.remove(web_path) timestamp = datetime.datetime.now() iso_time = timestamp.strftime('%Y-%m-%d %H:%M:%S') full_name = timestamp.strftime('%Y%m%d%H%M%S%f')+'.jpg' + web_name = 'web-'+full_name full_path = os.path.join(self.conf['path'], full_name) + web_path = os.path.join(self.conf['path'], web_name) stream = io.BytesIO() await loop.run_in_executor( executor, @@ -123,16 +124,6 @@ class Camera(BasePlugin): executor, functools.partial( web_image.save, web_path)) - thumb_image = await loop.run_in_executor( - executor, - functools.partial( - full_image.resize, - self._thumb, - PIL.Image.ANTIALIAS)) - await loop.run_in_executor( - executor, - functools.partial( - thumb_image.save, thumb_path)) stream.close() self._images.append((full_name, iso_time)) await self.bus.send(Message(self.name, @@ -146,13 +137,13 @@ class Camera(BasePlugin): camera.stop_preview() camera.close() while len(self._images) > 0: - file_name = self._images.popleft()[0] - file_path = os.path.join(self.conf['path'], - file_name) - os.remove(file_path) - if os.path.isfile(web_path): - os.remove(web_path) - if os.path.isfile(thumb_path): - os.remove(thumb_path) + full_name = self._images.popleft()[0] + full_path = os.path.join(self.conf['path'], full_name) + if os.path.isfile(full_path): + os.remove(full_path) + web_name = 'web_'+full_name + web_path = os.path.join(self.conf['path'], web_name) + if os.path.isfile(web_path): + os.remove(web_path) executor.shutdown(True) raise -- 2.34.1