Ejemplo n.º 1
0
def jpeg(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    compress = get_param(update, 6, 1, 10)
    if compress is None:
        return
    else:
        compress = 11 - compress
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return

    original = Image.open(path + filename + extension, 'r')
    if extension == ".jpg":
        original.save(path + filename + ".jpg",
                      quality=compress,
                      optimize=True)
    else:
        rgb_im = original.convert('RGB')
        rgb_im.save(path + "compressed.jpg", quality=compress, optimize=True)
        foreground = Image.open(path + "compressed.jpg")
        try:
            original.paste(foreground, (0, 0), original)
        except:
            pass
        original.save(path + filename + extension)
        os.remove(path + "compressed.jpg")
    send_image(update, path, filename, extension)
    os.remove(path + filename + extension)
Ejemplo n.º 2
0
def liquid(bot, update):
    current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S")
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    power = get_param(update, 60, 1, 100)
    if power is None:
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    identify = subprocess.Popen("identify " + path + filename + extension, stdout=subprocess.PIPE).communicate()[0]
    res = str(identify.split()[2])[2:-1]
    size = str(100 - (power / 1.3))
    name = filename + "-liquid"
    x = "convert " + path + filename + extension + " -liquid-rescale " + \
         size + "%x" + size + "% -resize " + res + "! " + path + name + extension
    subprocess.run(x, shell=True)
    if extension == ".mp4":
        mp4fix = "ffmpeg -loglevel panic -i " + path + name + extension + \
                  " -an -vf scale=trunc(iw/2)*2:trunc(ih/2)*2 \
                  -pix_fmt yuv420p -c:v libx264 -profile:v high -level:v 2.0 " \
                  + path + name + "_mp4" + extension + " -y"
        subprocess.run(mp4fix, shell=True)
        os.remove(path+name+extension)
        name = name + "_mp4"
    send_image(update, path, name, extension)
    os.remove(path+filename+extension)
    os.remove(path+name+extension)
    print(current_time, ">", "/liquid", ">", update.message.from_user.username)
    log_command(bot, update, current_time, "liquid")
Ejemplo n.º 3
0
def lego(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    size = get_param(update, 50, 1, 100)
    if size is None:
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("Can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    if extension == ".webp" or ".png":
        stick = "convert " + path + filename + extension + " -background white -flatten " + path + filename + extension
        subprocess.run(stick, shell=True)
    legofy.main(image_path=path + filename + extension,
                output_path=path + filename + "-lego" + extension,
                size=size,
                palette_mode=None,
                dither=False)
    send_image(update, path, filename + "-lego", extension)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-lego" + extension)
Ejemplo n.º 4
0
def kek(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    if update.message.reply_to_message is not None:
        kek_param = "".join(update.message.text[5:7])
    elif update.message.caption is not None:
        kek_param = "".join(update.message.caption[5:7])
    else:
        update.message.reply_text("You need an image for that")
        return
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("Can't get the image")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)

    if extension in [".mp4", ".gif"]:
        if kek_param == "-m":
            update.message.reply_text("Multikek unsupported for animations")
            return
        result = kekify_gifs(kek_param, filename, extension)
    else:
        _, _, result = kekify(kek_param, filename, extension, None)
    result.save(filename=path + filename + extension)
    result.close()
    if extension == ".mp4":
        filename = mp4_fix(path, filename)
    send_image(update, path, filename, extension)
    os.remove(path + filename + extension)
Ejemplo n.º 5
0
def liquid(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    power = get_param(update, 60, -100, 100)
    if power is None:
        return
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    power = (100 - (power / 1.3)) / 100
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    with Image(filename=path + filename + extension) as original:
        w, h = original.size
        new = Image()
        for i in range(len(original.sequence)):
            with original.sequence[i] as frame:
                img = Image(image=frame)
            img.liquid_rescale(int(w * power), int(h * power), delta_x=1)
            img.resize(w, h)
            new.sequence.append(img)
            img.close()
        new.save(filename=path + filename + extension)
        if extension == ".mp4":
            filename = mp4_fix(path, filename)
        send_image(update, path, filename, extension)
        new.close()
        os.remove(path + filename + extension)
Ejemplo n.º 6
0
def quote(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    id, name, text = get_message(update, context)
    if text == "" or text == None:
        update.message.reply_text("Type in some text!")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    profile_pic = get_profile_pic(context, filename, id, name)
    make_quote(profile_pic, filename, text, name)
    send_image(update, path, filename, ".jpg")
    os.remove(path + filename + ".jpg")
    os.remove(path + filename + "pfp.jpg")
Ejemplo n.º 7
0
def palette(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    name = filename + "-palette"
    colors = get_param(update, 4, 1, 10)
    if colors is None:
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    start_computing(path, filename, extension, colors, "flat")
    send_image(update, path, name, extension)
    os.remove(path + filename + extension)
    os.remove(path + name + extension)
Ejemplo n.º 8
0
def meme(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")

    if len(update.message.photo) > 0:
        args = update.message.caption.split(" ")
    else:
        args = update.message.text.split(" ")

    args = args[1:]

    if len(args) < 1:
        update.message.reply_text("Type in some text!")
        return

    font = fonts_dict["impact"]
    for i in fonts_dict:
        if "-" + i in args[0] or "-" + i[0] in args[0]:
            font = fonts_dict[i]
            args = args[1:]
            break

    if len(args) < 1:
        update.message.reply_text("Type in some text!")
        return

    initial_text = " ".join(args)
    split_text = initial_text.split("@", maxsplit=1)

    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    try:
        extension = get_image(bot, update, path, filename)
    except IndexError as e:
        update.message.reply_text("Can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return
    top_text, bottom_text = text_format(update, split_text)
    make_meme(top_text, bottom_text, filename, extension, path, font)
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    send_image(update, path, filename + "-meme", extension)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-meme" + extension)
Ejemplo n.º 9
0
def instagram_button(bot, update):
    current_time = datetime.strftime(datetime.now(), "%d.%m.%Y %H:%M:%S")
    query = update.callback_query
    chosen_filter, extension = update.callback_query.data.split(",")
    filter_name = str(chosen_filter)[5:]
    user = query.from_user.username
    bot.editMessageText(text="%s selected: %s\nProcessing..." %
                        (user, filter_name),
                        chat_id=query.message.chat_id,
                        message_id=query.message.message_id)
    query.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    try:
        getattr(modules.instagram_filters, chosen_filter)(path, filename,
                                                          extension)
    except:
        raise Exception("Instagram error")
    send_image(query, path, filename + "-" + filter_name, extension)
    os.remove(path + filename + extension)
    os.remove(path + filename + "-" + filter_name + extension)
    print(current_time, ">", "/instagram", ">", user)
    log_command(bot, update, current_time, "instagram")
Ejemplo n.º 10
0
def kek(bot, update):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    if update.message.reply_to_message is not None:
        kek_param = "".join(update.message.text[5:7])
    elif update.message.caption is not None:
        kek_param = "".join(update.message.caption[5:7])
    else:
        update.message.reply_text("You need an image for that!")
        return
    try:
        extension = get_image(bot, update, path, filename)
    except:
        update.message.reply_text("Can't get the image! :(")
        return
    if extension not in extensions:
        update.message.reply_text("Unsupported file, onii-chan!")
        return False
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
    result = kekify(update, kek_param, filename, extension)
    send_image(update, path, result, extension)
    os.remove(path + result + extension)
    os.remove(path + filename + extension)
Ejemplo n.º 11
0
def fap(update, context):
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
    try:
        extension = get_image(update, context, path, filename)
    except:
        update.message.reply_text("I can't get the image! :(")
        return
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)

    with Image(filename=path + filename + extension) as decal:
        decal.resize(320, 172)
        w, h = decal.size
        decal.virtual_pixel = 'transparent'
        source_points = ((0, 0), (w, 0), (w, h), (0, h))
        with Image(filename=launchpad_gif) as template_gif:
            new = Image()
            for i in range(len(template_gif.sequence)):
                with template_gif.sequence[i] as frame:
                    img = Image(image=frame)
                    img.delay = 6
                destination_points = (coords_by_frame[i])
                order = chain.from_iterable(
                    zip(source_points, destination_points))
                arguments = list(chain.from_iterable(order))
                decal_current = Image(image=decal)
                decal_current.matte_color = "rgba(255, 255, 255, 0)"
                decal_current.distort('perspective', arguments)
                img.composite(decal_current, left=0, top=0)
                new.sequence.append(img)
                decal_current.close()
                img.close()
            new.save(filename=path + "result.mp4")
            result_filename = mp4_fix(path, "result")
            send_image(update, path, result_filename, ".mp4")
            new.close()
            os.remove(path + result_filename + ".mp4")
            os.remove(path + filename + extension)