예제 #1
0
async def google_img(message: Message):
    if (GCS_API_KEY and GCS_IMAGE_E_ID) is None:
        await message.edit(REQ_ERR, disable_web_page_preview=True)
        return
    if os.path.exists(PATH):
        shutil.rmtree(PATH, ignore_errors=True)

    fetcher = GIS(GCS_API_KEY, GCS_IMAGE_E_ID)
    query = message.input_str
    search = {'q': query,
              'num': 5,
              'safe': "off",
              'fileType': "jpg",
              'imgType': "photo",
              'imgSize': "MEDIUM"}
    await message.edit("`Processing...`")
    fetcher.search(search_params=search)
    for image in fetcher.results():
        image.download(PATH)
    if not os.path.exists(PATH):
        await message.edit("Oops, No Results Found")
        return
    ss = []
    for img in os.listdir(PATH):
        imgs = PATH + img
        ss.append(InputMediaPhoto(str(imgs)))
        if len(ss) == 5:
            break
    await message.reply_chat_action("upload_photo")
    await message.reply_media_group(ss, True)
    shutil.rmtree(PATH, ignore_errors=True)
    await message.delete()
예제 #2
0
async def google_img(message: Message):
    if (GCS_API_KEY and GCS_IMAGE_E_ID) is None:
        await message.edit(REQ_ERR, disable_web_page_preview=True)
        return
    fetcher = GIS(GCS_API_KEY, GCS_IMAGE_E_ID)
    query = message.input_str
    search = {
        'q': query,
        'num': 9,
        'safe': "off",
        'fileType': "jpg",
        'imgType': "photo",
        'imgSize': "HUGE"
    }
    await message.edit("`Processing...`")
    fetcher.search(search_params=search)
    for image in fetcher.results():
        image.download(PATH)
    if not os.path.exists(PATH):
        await message.edit("Oops, No Results Found")
        return
    for img in os.listdir(PATH):
        imgs = PATH + img
        await userge.send_photo(chat_id=message.chat.id, photo=imgs)
    shutil.rmtree(PATH, ignore_errors=True)
    await message.delete()
예제 #3
0
async def google_img(message: Message):
    if (GCS_API_KEY and GCS_IMAGE_E_ID) is None:
        await message.edit(REQ_ERR, disable_web_page_preview=True)
        return
    if os.path.exists(PATH):
        shutil.rmtree(PATH, ignore_errors=True)

    fetcher = GIS(GCS_API_KEY, GCS_IMAGE_E_ID)
    query = message.input_str
    search = {
        "q": query,
        "num": 10,
        "safe": "off",
        "fileType": "jpg",
        "imgType": "photo",
        "imgSize": "LARGE",
    }
    await message.edit("`Processing...`")
    fetcher.search(search_params=search)
    for image in fetcher.results():
        image.download(PATH)
    if not os.path.exists(PATH):
        await message.edit("Oops, No Results Found")
        return
    ss = []
    for img in os.listdir(PATH):
        imgs = PATH + img
        image = Image.open(imgs)
        if not (image.height <= 1280 and image.width <= 1280):
            image.thumbnail((1280, 1280), Image.ANTIALIAS)
            a_dex = image.mode.find("A")
            if a_dex != -1:
                new_im = Image.new("RGB", image.size, (255, 255, 255))
                new_im.paste(image, mask=image.split()[a_dex])
                new_im.save(imgs, "JPEG")
        ss.append(InputMediaPhoto(str(imgs)))
        if len(ss) == 10:
            break
    await message.reply_chat_action("upload_photo")
    await message.reply_media_group(ss, True)
    shutil.rmtree(PATH, ignore_errors=True)
    await message.delete()