コード例 #1
0
async def watermark_process(msg, photo, position, color, opacity, font, fsize,
                            text):
    pic_bytes = BytesIO()
    await photo.download(pic_bytes)
    color_with_opacity = color.copy()
    color_with_opacity.append(opacity)
    watermarked_photo = await async_image_process(msg.bot.loop, pic_bytes,
                                                  position,
                                                  tuple(color_with_opacity),
                                                  f"fonts/{font}.ttf",
                                                  int(fsize), text)
    sended_pic = await msg.bot.send_photo(msg.chat.id, watermarked_photo)
    await sended_pic.reply(**routes_messages.get("sendpic"))
コード例 #2
0
ファイル: settings.py プロジェクト: sysadmin-tools/wtrmarkbot
from keyboards.inline.menu import settings_menu
from middlewares.userdata import userdata_required
from aiogram.types import Message, CallbackQuery
from models.user import User
from .routes import SettingsRoute
from consts import TEXT_COLORS, POSITIONS, FONTS, MAX_FONT_SIZE
from messages import routes_messages
from states.settings import SetColor, SetPosition, SetOpacity, SetFont, SetFontSize, SetText
from utlis.helpers import validate_number, check_in, get_key_by_value

configure_position = SettingsRoute("position", POSITIONS.get,
                                   routes_messages.get("position"),
                                   SetPosition)

configure_color = SettingsRoute(
    "color", lambda text: get_key_by_value(TEXT_COLORS, TEXT_COLORS.get(text)),
    routes_messages.get("color"), SetColor)

configure_opacity = SettingsRoute("opacity", validate_number,
                                  routes_messages.get("opacity"), SetOpacity)

configure_font = SettingsRoute("font", lambda text: check_in(text, FONTS),
                               routes_messages.get("font"), SetFont)

configure_fontsize = SettingsRoute(
    "fontsize", lambda text: validate_number(text, MAX_FONT_SIZE),
    routes_messages.get("fontsize"), SetFontSize)

configure_text = SettingsRoute("text", lambda text: text,
                               routes_messages.get("text"), SetText)
コード例 #3
0
async def from_command(msg: Message):
    await msg.answer(**routes_messages.get("starting"))
    await SWatermarkState.sget_pic.set()
コード例 #4
0
async def from_callback(callback_query: CallbackQuery):
    await callback_query.bot.send_message(chat_id=callback_query.from_user.id,
                                          **routes_messages.get("starting"))
    await SWatermarkState.sget_pic.set()
コード例 #5
0
async def get_picture(msg: Message, state: FSMContext):
    last_photo = msg.photo[-1]
    await state.update_data(photo=last_photo)
    await msg.reply(**routes_messages.get("position"))
    await SetWatermark.next()
コード例 #6
0
from aiogram.types import Message, CallbackQuery
from aiogram.dispatcher import FSMContext
from states.watermark import SetWatermark
from .routes import TextRoute
from messages import routes_messages
from consts import POSITIONS, TEXT_COLORS, FONTS, MAX_FONT_SIZE
from utlis.helpers import validate_number, check_in
from utlis.image_converter import watermark_process

get_position = TextRoute("position", POSITIONS.get,
                         routes_messages.get("position"),
                         routes_messages.get("color"))
get_color = TextRoute("color", TEXT_COLORS.get, routes_messages.get("color"),
                      routes_messages.get("opacity"))
get_opacity = TextRoute("opacity", validate_number,
                        routes_messages.get("opacity"),
                        routes_messages.get("font"))
get_font = TextRoute("font", lambda text: check_in(text, FONTS),
                     routes_messages.get("font"),
                     routes_messages.get("fontsize"))
get_fontsize = TextRoute("fontsize",
                         lambda text: validate_number(text, MAX_FONT_SIZE),
                         routes_messages.get("fontsize"),
                         routes_messages.get("text"))


async def starting_from_command(msg: Message):
    await msg.answer(**routes_messages.get("starting"))
    await SetWatermark.get_pic.set()