Esempio n. 1
0
    def process(owner, content):
        im_data = io.BytesIO(content)
        im_copy = io.BytesIO(content)
        im = Image.open(im_data)
        cf = imaging.ColorFinder(im)
        top = imaging.ColorUtil.generate_color_panes(tuple(cf.strategy_enhanced_complements()))
        output = StringIO.StringIO()
        top.save(output, format="JPEG")
        palette = io.BytesIO(output.getvalue())
        palette_copy = io.BytesIO(output.getvalue())
        output.close()

        upload = Picture(parent=Picture.picture_key(owner))
        upload.owner = owner
        file_name = files.blobstore.create(mime_type='image/jpeg')
        with files.open(file_name, 'a') as f:
            f.write(im_copy.read())
        files.finalize(file_name)
        picture_blob_key = files.blobstore.get_blob_key(file_name)
        upload.picture = str(picture_blob_key)

        palette_name = files.blobstore.create(mime_type='image/jpeg')
        with files.open(palette_name, 'a') as f:
            f.write(palette_copy.read())
        files.finalize(palette_name)
        palette_blob_key = files.blobstore.get_blob_key(palette_name)
        upload.palette = str(palette_blob_key)
        upload.put()

        return palette
Esempio n. 2
0
  def _render_template(self):
    # """Render the main page template."""

    pictures_query = Picture.query(ancestor=Picture.picture_key(str(self.userid))).order(-Picture.date)
    pictures = pictures_query.fetch(3) 

    template_values = {'userId': self.userid, 'pictures': pictures}

    template = jinja_environment.get_template('templates/index.html')
    self.response.out.write(template.render(template_values))