From: Calin Crisan Date: Sat, 16 Nov 2013 12:13:39 +0000 (+0200) Subject: added support for picture resizing X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=16ee56b32a076bdfeca889af3a677bb664485bea;p=motioneye-debian added support for picture resizing --- diff --git a/doc/requirements.txt b/doc/requirements.txt index 1cc3e5b..488513e 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,6 +1,7 @@ python >= 2.6 tornado jinja2 +pil ffmpeg motion diff --git a/src/handlers.py b/src/handlers.py index fb223a0..5bd95e8 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -19,8 +19,10 @@ import base64 import json import logging import os +import StringIO from tornado.web import RequestHandler, HTTPError, asynchronous +from PIL import Image import config import mediafiles @@ -690,11 +692,24 @@ class PictureHandler(BaseHandler): else: content = mediafiles.get_media_content(camera_config, filename) - - # TODO add support for ?width=, ?height= - self.set_header('Content-Type', 'image/jpeg') - self.finish(content) + + width = self.get_argument('width', None) + height = self.get_argument('height', None) + + if width is None and height is None: + return self.finish(content) + + sio = StringIO.StringIO(content) + image = Image.open(sio) + + width = width and int(width) or image.size[0] + height = height and int(height) or image.size[1] + + image.thumbnail((width, height), Image.ANTIALIAS) + + image.save(self, format='JPEG') + self.finish() class MovieHandler(BaseHandler): diff --git a/static/js/main.js b/static/js/main.js index 2973190..f1fd325 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -1381,6 +1381,12 @@ function runMediaDialog(cameraId, mediaType) { var keys = Object.keys(groups); keys.sort(); + /* add a temporary div to compute 3em in px */ + var tempDiv = $('
'); + $('div.modal-container').append(tempDiv); + var height = tempDiv.height(); + tempDiv.remove(); + keys.forEach(function (key) { if (key) { var groupDiv = $('
' + key + '
'); @@ -1393,7 +1399,7 @@ function runMediaDialog(cameraId, mediaType) { entries.forEach(function (entry, pos) { var entryDiv = $('
'); - var previewImg = $(''); + var previewImg = $(''); entryDiv.append(previewImg); var downloadButton = $('
download
');