def merch(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 if extension not in extensions: update.message.reply_text("Unsupported file") return False update.message.chat.send_action(ChatAction.UPLOAD_PHOTO) templates_list = list(templates_dict.keys()) if len(context.args) > 0: if context.args[0] in templates_list: amount = 1 template = True else: amount = get_param(update, 1, 1, 10) template = False else: amount = get_param(update, 1, 1, 10) template = False image = path + filename + extension photos = [] upload_files = [] for i in range(amount): if template is True: product = context.args[0] else: product = random.choice(templates_list) templates_list.remove(product) result_image = make_merch(image, templates_path, templates_dict[product], templates_dict[product]["offset"]) result_image.save(path + "merch" + str(i) + ".jpg") image_to_attach = "merch" + str(i) + ".jpg" attach_name = "".join( random.choice("abcdef1234567890") for x in range(16)) photos.append({"type": "photo", "media": "attach://" + attach_name}) upload_files.append( (attach_name, (image_to_attach, open(path + image_to_attach, "rb")))) requests.post("https://api.telegram.org/bot" + token + "/sendMediaGroup", params={ "chat_id": update.message.chat.id, "media": json.dumps(photos) }, files=upload_files, timeout=120) os.remove(path + filename + extension) return amount
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)
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)
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")
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)
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)
def nya(update, context): update.message.chat.send_action(ChatAction.UPLOAD_PHOTO) amount = get_param(update, 1, 1, 10) photos = [] upload_files = [] for i in range(amount): random_image = random.choice(files) attach_name = "".join( random.choice("abcdef1234567890") for x in range(16)) photos.append({"type": "photo", "media": "attach://" + attach_name}) upload_files.append( (attach_name, (random_image, open(path + random_image, "rb")))) requests.post("https://api.telegram.org/bot" + token + "/sendMediaGroup", params={ "chat_id": update.message.chat.id, "media": json.dumps(photos) }, files=upload_files, timeout=120) return amount