1
# -*- coding: utf-8 -*-
10
from sys import maxint
14
import werkzeug.exceptions
16
import werkzeug.wrappers
20
from openerp.osv import fields
21
from openerp.addons.website.models import website
22
from openerp.addons.web import http
23
from openerp.addons.web.http import request, LazyResponse
25
logger = logging.getLogger(__name__)
27
# Completely arbitrary limits
28
MAX_IMAGE_WIDTH, MAX_IMAGE_HEIGHT = IMAGE_LIMITS = (1024, 768)
31
class EmbeddedPicture(openerp.addons.web.controllers.main.Home):
33
@http.route('/embedded/gen_img', type='http', auth='user', methods=['POST'])
34
def gen_img(self, func, upload):
36
img_tag = message = None
38
image_data = upload.read()
39
image = Image.open(cStringIO.StringIO(image_data))
41
if w*h > 42e6: # Nokia Lumia 1020 photo resolution
43
u"Image size excessive, uploaded images must be smaller "
44
u"than 42 million pixel")
46
data_uri = image_data.encode('base64').replace('\n', '')
47
ext = upload.filename.split('.')[-1].lower()
48
img_tag = '<img src="data:image/{0};base64,{1}">'.format(ext, data_uri)
50
logger.exception("Failed to upload image to attachment")
53
return """<script type='text/javascript'>
54
window.parent['%s'](%s, %s);
55
</script>""" % (func, json.dumps(img_tag), json.dumps(message))
57
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4: