Esempio n. 1
0
def create_thumbnail(uuid):

    photo = Photo.query.filter(Photo.uuid == uuid).one()

    try:
        logging.info('processing photo {} '.format(photo.uuid))

        # resize and add transparent background
        size = (320, 320)
        im = Image.open(urlopen(photo.url))
        im.thumbnail(size, Image.ANTIALIAS)
        background = Image.new('RGBA', size, (255, 255, 255, 0))
        background.paste(im, (int(
            (size[0] - im.size[0]) / 2), int((size[1] - im.size[1]) / 2)))
        relative_filename = Path(uuid).with_suffix('.png')
        filename = Path('/waldo-app-thumbs', uuid).with_suffix('.png')
        background.save(filename, "png")

        # todo: save in the location from the environment
        thumbnail = Thumbnail(photo.uuid, 320, 320, str(relative_filename))

        db_session.add(thumbnail)
        photo.status = 'completed'
        db_session.add(photo)
        db_session.commit()

    except Exception as e:
        logging.error('generation error {} {}'.format(uuid, str(e)))
        photo.status = 'failed'
        db_session.add(photo)
        db_session.commit()
Esempio n. 2
0
def show_public_photo(request, key):
    extra_context = {
        'object_list': Thumbnail.all().order('-photo_date_added'),
        'viewed_username': '******',
    }
    return object_detail(request, Photo.all(), key,
        template_name='photo/public-show.html',
        template_object_name='photo',
        extra_context=extra_context)
Esempio n. 3
0
def create_and_save_new_photo_with_thumb(user, file_content, description=u''):
    img = images.Image(file_content)
    
    anim = get_anim_type_for_photo_size(img.width, img.height)
    thumb_anim = anim.thumb_anim
    
    # img.resize()
    thumb_img = images.resize(file_content, thumb_anim.photo_width, thumb_anim.photo_height)
    # thumb_img = img.execute_transforms(output_encoding=images.JPEG)
    
    # raise Exception(db.Blob(img))
    # raise Exception('%s\n%s' % (dir(img), img.__dict__))
    photo_file = PhotoFile(
        blob=db.Blob(file_content)
    )
    photo_file.put()
    
    photo = Photo(
        file=photo_file,
        user=user,
        anim_type=anim,
        anim_frame_time=0.25,
        description=description
    )
    photo.set_denormalized_fields()
    photo.put()
    
    thumb_file = ThumbnailFile(
        blob=thumb_img
    )
    thumb_file.put()
    
    thumb = Thumbnail(
        file=thumb_file,
        photo=photo
    )
    thumb.set_denormalized_fields()
    thumb.put()
    
    return photo
Esempio n. 4
0
def users_photo(request, username, photo_key):
    viewed_user = User.get_user_by_username_or_404(username)
    photo = get_object_or_404(Photo, photo_key)
    
    if photo.user != viewed_user:
        raise Http404('Object does not exist!')
    
    extra_context = {
        'viewed_user': viewed_user,
        'photo': photo,
        'viewed_username': username
    }
    
    return object_list(request,
        queryset=Thumbnail.all().filter('photo_user', viewed_user).order('-photo_date_added'),
        template_name='photo/show.html',
        extra_context=extra_context
    )
Esempio n. 5
0
def users_page(request, username):
    viewed_user = User.get_user_by_username_or_404(username)
    
    photo = None
    fetched_photo_list = Photo.all().filter('user', viewed_user).order('-date_added').fetch(1)
    if fetched_photo_list:
        photo = fetched_photo_list[0]
    
    extra_context = {
        'viewed_user': viewed_user,
        'photo': photo,
        'viewed_username': username
    }
    
    return object_list(request,
        queryset=Thumbnail.all().filter('photo_user', viewed_user).order('-photo_date_added'),
        template_name='photo/show.html',
        extra_context=extra_context
    )
Esempio n. 6
0
    def post(self):
        album_key = ndb.Key(urlsafe=self.request.get('key'))
        if album_key is not None:
            previous_thumbnails = Thumbnail.query(ancestor=album_key).fetch()
            for previous_thumbnail in previous_thumbnails:  # should be one of these at most.
                previous_thumbnail_key = ndb.Key(urlsafe=previous_thumbnail.ukey())
                previous_thumbnail_key.delete()
            upload_files = self.get_uploads()  # 'file' is file upload field in the form
            blob_info = upload_files[0]
            thumbnail = Thumbnail(parent=album_key, image_blob=blob_info.key())
            thumbnail.populate(serving_url=images.get_serving_url(blob_info.key()))
            thumbnail.put()

            album = album_key.get()
            album.thumbnail_serving_url = thumbnail.serving_url
            album.put()

            album_key = ndb.Key(urlsafe=self.request.get('key'))  # No idea why I have to add this line in again
            self.redirect('/add-album?key=%s' % album_key.urlsafe())

        else:
            #raise some error here.
            self.redirect('/')