Telegram Media Branding Bot
I built a Telegram bot that puts one of 60 branded watermarks on photos, videos and GIFs when someone replies to them with a command.
The problem
The community's branded characters and logos had to go onto photos, videos and GIFs quickly, straight from the chat, without anyone opening an editing app.
How I built it
An aiogram 3 bot: reply to any photo, video or GIF with a command named after a watermark and the bot sends back the branded version. Each of the 60 watermark files is its own command with its own placement and size rules (corner characters, bottom-centre characters, full-width text, full-frame overlays). Photos are composited with Pillow, videos and GIFs go through an FFmpeg filter graph, and extra commands add fisheye and scanline effects. Access can be locked to approved groups and admin DMs, and a semaphore keeps the number of simultaneous jobs under control.
What got hard
- Watermarks came out the wrong size on portrait photos, as the client's own examples showed.
I replaced fixed sizes with scale multipliers relative to the frame's shorter side, capped so a character always fits inside the frame, and built a visual test sheet that renders watermarks on portrait and landscape backgrounds (25 saved renders).
- Video overlays are fragile: FFmpeg's expression-based scaling was unreliable on some builds, and an oversized upload could swamp the bot.
I probe the video and the watermark first and compute exact pixel sizes (kept even, as video codecs need), reject media over 3.5 megapixels or 180 seconds up front, and cap photos at 40 megapixels to block decompression-bomb files.
The result
60 watermark commands plus fisheye and scanline effects, with a visual test set of 25 saved photo renders and a separate video and GIF test script (110 saved test outputs).
The ← and → keys turn the page too.