Skip to content

Commit

Permalink
Update pixelateTG.py
Browse files Browse the repository at this point in the history
  • Loading branch information
arbadacarbaYK authored May 30, 2024
1 parent b26fdb6 commit 19e6e86
Showing 1 changed file with 45 additions and 27 deletions.
72 changes: 45 additions & 27 deletions pixelateTG.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,55 @@ def pixelate_faces(update: Update, context: CallbackContext) -> None:
file = context.bot.get_file(file_id)
file_name = file.file_path.split('/')[-1]
if file_name.endswith('.gif'):
file_name = file_name[:-4] + '.jpg' # convert gif extension to jpg
photo_path = f"downloads/{file_name}"
file.download(photo_path)

image = cv2.imread(photo_path)
faces = detect_heads(image)

if not faces:
update.message.reply_text('No faces detected in the image.')
return

keyboard = [
[InlineKeyboardButton("🤡 Clowns", callback_data=f'clowns_overlay_{session_id}'),
InlineKeyboardButton("😂 Liotta", callback_data=f'liotta_overlay_{session_id}'),
InlineKeyboardButton("☠️ Skull", callback_data=f'skull_overlay_{session_id}')],
[InlineKeyboardButton("🐈‍⬛ Cats", callback_data=f'cats_overlay_{session_id}'),
InlineKeyboardButton("🐸 Pepe", callback_data=f'pepe_overlay_{session_id}'),
InlineKeyboardButton("🏆 Chad", callback_data=f'chad_overlay_{session_id}')],
[InlineKeyboardButton("⚔️ Pixel", callback_data=f'pixelate_{session_id}'),
InlineKeyboardButton("CLOSE ME", callback_data=f'cancel_{session_id}')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
user_data[session_id] = {'photo_path': photo_path, 'user_id': update.message.from_user.id}

update.message.reply_text('Press buttons until happy', reply_markup=reply_markup)
update.message.delete()
# Convert GIF to a series of JPG frames
gif_path = f"downloads/{file_name}"
file.download(gif_path)
frames = imageio.mimread(gif_path)
jpg_frames = [imageio.imwrite(f"downloads/{session_id}_{i}.jpg", frame) for i, frame in enumerate(frames)]
photo_paths = [f"downloads/{session_id}_{i}.jpg" for i in range(len(jpg_frames))]

# Process each frame separately
processed_frames = [process_image(photo_path, update.message.from_user.id, session_id, context.bot) for photo_path in photo_paths]
processed_gif_path = f"processed/{update.message.from_user.id}_{session_id}.gif"
imageio.mimsave(processed_gif_path, processed_frames)

# Send the processed GIF
context.bot.send_animation(chat_id=update.message.from_user.id, animation=open(processed_gif_path, 'rb'))

# Clean up temporary files
for photo_path in photo_paths:
os.remove(photo_path)
os.remove(gif_path)
else:
photo_path = f"downloads/{file_name}"
file.download(photo_path)

image = cv2.imread(photo_path)
faces = detect_heads(image)

if not faces:
update.message.reply_text('No faces detected in the image.')
return

keyboard = [
[InlineKeyboardButton("🤡 Clowns", callback_data=f'clowns_overlay_{session_id}'),
InlineKeyboardButton("😂 Liotta", callback_data=f'liotta_overlay_{session_id}'),
InlineKeyboardButton("☠️ Skull", callback_data=f'skull_overlay_{session_id}')],
[InlineKeyboardButton("🐈‍⬛ Cats", callback_data=f'cats_overlay_{session_id}'),
InlineKeyboardButton("🐸 Pepe", callback_data=f'pepe_overlay_{session_id}'),
InlineKeyboardButton("🏆 Chad", callback_data=f'chad_overlay_{session_id}')],
[InlineKeyboardButton("⚔️ Pixel", callback_data=f'pixelate_{session_id}'),
InlineKeyboardButton("CLOSE ME", callback_data=f'cancel_{session_id}')]
]
reply_markup = InlineKeyboardMarkup(keyboard)
user_data[session_id] = {'photo_path': photo_path, 'user_id': update.message.from_user.id}

update.message.reply_text('Press buttons until happy', reply_markup=reply_markup)
update.message.delete()
else:
update.message.reply_text('Please send either a photo or a GIF.')



def pixelate_command(update: Update, context: CallbackContext) -> None:
if update.message.reply_to_message and update.message.reply_to_message.photo:
session_id = str(uuid4())
Expand Down

0 comments on commit 19e6e86

Please sign in to comment.