Exemplo n.º 1
0
def thumbnail(input_filepath, uri):
    thumbnails = []
    for size_tuple in constants.THUMBNAIL_SIZE_TUPLE_TO_SIZE_CODE:
        size_code = constants.THUMBNAIL_SIZE_TUPLE_TO_SIZE_CODE[size_tuple]
        filename, fpath = utils.thumbnail(input_filepath, uri, size_tuple)
        touch_thumbnail(uri, filename, size_code)
        thumbnails.append((filename, fpath))
    return thumbnails
Exemplo n.º 2
0
 def parse_image(image):
     if image:
         tmp = image.split(b'\r\n\r\n', 1)
         if len(tmp) == 2:
             src_image = tmp[1].rstrip(b'\r\n')
             if len(src_image) > 0:
                 thb_image = thumbnail(src_image)
                 return src_image, thb_image, tmp[0].decode('utf-8')
     return None, None, None
Exemplo n.º 3
0
 def thumbnail(self):
     return thumbnail(self.image, self.cropping)
Exemplo n.º 4
0
 def dehydrate_item_thumb(self, bundle):
     default_image = bundle.obj.item.get_default_image()
     if not default_image is None:
         return thumbnail(default_image, '80x80', crop='center').url
Exemplo n.º 5
0
 def thumbnail(self):
     return thumbnail(self.image, self.cropping)
Exemplo n.º 6
0
def parseInlineQuery(bot, update):
    q = update.inline_query.query

    # actual inline query results to present to the user
    results = []

    if q.lower() == 'gen':
        # if it's simply 'gen', we fill our results with a generated SIGARETTO
        restext = gen.generate()
        results.append(
            telegram.InlineQueryResultArticle(
                type='article',
                id=uuid.uuid4(),
                thumb_url=utils.thumbnail(),
                thumb_width=AVATAR_SIZE,
                thumb_height=AVATAR_SIZE,
                title='SIGARETTO #GENERATED',
                description=restext[:200],
                input_message_content=telegram.InputTextMessageContent(
                    message_text=restext, parse_mode=None)))

    else:
        # we have to search
        # search results:
        res = []

        # try to detect if user asked for a SIGA id or a regex search (starting with "-r ")
        asked_siga = parseSigaNumber(q)
        if asked_siga:
            # yes, pick it
            res = [getS(sl, asked_siga)]
        elif q.startswith('-r '):
            # no, but a regex search is invoked
            q = q[3:]
            res = regexSearch(q, sl)
        else:
            # neither special case is required, normal search
            res = normalSearch(q, sl)

        # search completed, we now have all matching results in res, which may or may not be empty
        if not res:
            # empty, send bogus SIGA
            restext = random.choice(notfound.notfound)
            if "%s" in restext:
                restext = restext % q
            results.append(
                telegram.InlineQueryResultArticle(
                    type='article',
                    id=uuid.uuid4(),
                    thumb_url=utils.thumbnail(),
                    thumb_width=AVATAR_SIZE,
                    thumb_height=AVATAR_SIZE,
                    title='SIGARETTO #NOT_FOUND',
                    description=restext[:200],
                    input_message_content=telegram.InputTextMessageContent(
                        message_text=restext, parse_mode=None)))

        else:
            # non-empty, build list of actual results
            for i in res:
                restext = i['text']
                sid = i['id']
                authorid = i['authorid']

                # if sid in img_cache:
                #     results.append(telegram.InlineQueryResultPhoto(
                #         type='photo',
                #         id=sid,
                #         photo_url=img_url(sid),
                #         thumb_url=utils.thumbnail(authorid),
                #         title='SIGARETTO #%d' % sid,
                #         description=restext[:200],
                #         caption=restext[:200],
                #         photo_file_id=img_cache[sid],
                #     ))
                # elif sid in audio_cache:
                #     results.append(telegram.InlineQueryResultAudio(
                #         type='audio',
                #         id=sid,
                #         audio_url=audio_url(sid),
                #         title='SIGARETTO #%d' % sid,
                #         caption=restext[:200]
                #         # to be completed with other parameters
                #     ))

                fulltext = restext
                if sid in videos:
                    fulltext = restext + "\n\n" + videos[sid]
                results.append(
                    telegram.InlineQueryResultArticle(
                        type='article',
                        id=sid,
                        thumb_url=utils.thumbnail(authorid),
                        thumb_width=AVATAR_SIZE,
                        thumb_height=AVATAR_SIZE,
                        title='SIGARETTO #%d' % sid,
                        description=restext[:200],
                        input_message_content=telegram.InputTextMessageContent(
                            message_text=fulltext, parse_mode=None)))

    # all cases examined, we now have a results array and can answer the query
    bot.answerInlineQuery(update.inline_query.id, results, cache_time=0)

    logger.info(update)
Exemplo n.º 7
0
 def dehydrate_image(self, bundle):
     return thumbnail(bundle.obj.image, '400x400', crop='center').url
Exemplo n.º 8
0
 def dehydrate_thumb(self, bundle):
     return thumbnail(bundle.obj.image, '220x220', crop='center').url
Exemplo n.º 9
0
 def dehydrate_default_image(self, bundle):
     default_image = bundle.obj.get_default_image()
     if default_image is None:
         default_image = 'http://vk.com/images/question_a.gif'
     return thumbnail(default_image, '150x150', crop='center').url
            asc_idx = cls_arr[:, 2].argsort()
            # verify ascending
            if len(cls_arr[asc_idx][:, 2]) > 5:
                assert cls_arr[asc_idx][:, 2][0] < cls_arr[asc_idx][:, 2][5]
            sort_num = 0
            for img_path in cls_arr[asc_idx][:, 0]:
                sort_num += 1
                shutil.copy2(
                    img_path,
                    os.path.join(
                        cls_dir, "{}_{}".format(sort_num,
                                                img_path.split('/')[-1])))


if __name__ == "__main__":

    parser = argparse.ArgumentParser(description='Clustering deep feature')
    parser.add_argument('--feature_path', required=True)
    parser.add_argument('--clustering_cnt', required=True)
    parser.add_argument('--target_dir', required=True)

    args = parser.parse_args()

    C = Cluster(args.feature_path, args.clustering_cnt, args.target_dir)
    C.load_feature()
    C.train()
    C.centroid_distance()
    C.generate_target()

    thumbnail(args.target_dir)
Exemplo n.º 11
0
 def get_avatar_thumb(self, size='40x40'):
     return thumbnail(self.get_avatar(), size, crop='center')