manga / main.py
sayed555's picture
Update main.py
cf0d1f3 verified
import discord
from discord.ext import commands
from PIL import Image, ImageChops
import io
import os
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
def remove_watermark(image_bytes, watermark_path):
try:
original = Image.open(io.BytesIO(image_bytes)).convert("RGBA")
watermark = Image.open(watermark_path).convert("RGBA")
watermark = watermark.resize(original.size)
result = ImageChops.difference(original, watermark)
output = io.BytesIO()
result.save(output, format="PNG")
output.seek(0)
return output
except Exception as e:
print(f"Error processing image: {e}")
return None
@bot.event
async def on_ready():
print(f'البوت جاهز وشغال باسم {bot.user}')
@bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.attachments:
for attachment in message.attachments:
if attachment.filename.lower().endswith(('.png', '.jpg', '.jpeg')):
await message.channel.send('جاري معالجة الصورة وإزالة العلامة المائية لحظة واحدة')
image_bytes = await attachment.read()
processed_image = remove_watermark(image_bytes, 'watermark_sample.png')
if processed_image:
await message.channel.send(file=discord.File(fp=processed_image, filename='unwatermarked.png'))
else:
await message.channel.send('حصلت مشكلة في معالجة الصورة تأكد من ملف العلامة المائية')
await bot.process_commands(message)
bot.run('MTQ4NDk0NDE1ODg3ODg2MzUzMA.GYa8fr.iNIRXBgp_JRHwYgXKXzC_HQbhex1YOAq4cgdkI')