惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
月光博客
月光博客
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
U
Unit 42
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
Martin Fowler
Martin Fowler
N
Netflix TechBlog - Medium
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
V
Visual Studio Blog
腾讯CDC
IT之家
IT之家

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I Built an AI Emoji Generator with Next.js 15 & Cloud...
xiangbin zhu · 2026-05-09 · via DEV Community

Every emoji tool I could find did the same thing: let you pick from a fixed set of combos.

Emoji Kitchen has 50K+ monthly visitors exactly because people love emoji combinations. But it's just a lookup table — Google pre-rendered ~40,000 combinations and serves them as static images. There's no AI, no creativity, no support for combinations that don't exist in the dataset.

I wanted to build something different: type two emoji, get a brand-new AI-generated image that's never existed before, with a transparent background so you can actually use it anywhere.

Here's how Forgemoji works under the hood.

A quick note on scope: I'm a UI/UX designer by trade, so I handled the full product — interface design, interaction design, and the engineering. The stack choices below reflect someone who thinks in user flows first and infrastructure second.


The Architecture: Three Layers

I ended up with a three-layer generation system, each progressively more capable (and more expensive):

Layer 1 — Static lookup     ← REMOVED (copyright risk)
Layer 2 — Text-to-image     ← Primary path (free, ~30s)
Layer 3 — Image-to-image    ← Upload your photo, fuse it with an emoji (~120s, async)

Enter fullscreen mode Exit fullscreen mode

Layer 1 was the original plan — use Google's pre-rendered emoji kitchen images. I killed it on day 5 after reading Google's image attribution policy more carefully. The risk wasn't worth it.


Layer 2: Text-to-Image with a Provider Fallback Chain

The core challenge with T2I emoji generation is: how do you make the model output something that actually looks like an emoji?

The naive approach — "🐱 + 🔥" — produces whatever the model thinks a cat fire is. Usually it's a realistic cat on fire. Not what you want.

Prompt Engineering: Descriptions > Unicode

I built a mapping table (emoji-prompt-map.ts) that translates emoji into concrete visual descriptions:

const EMOJI_DESCRIPTIONS: Record<string, string> = {
  '😀': 'round yellow face, wide open grin showing teeth, simple oval dot eyes',
  '🔥': 'bright orange and red flame, cartoon style, rounded base',
  '🐱': 'cute round cat face, large eyes, small pink nose, whiskers',
  // 200+ entries...
}

Enter fullscreen mode Exit fullscreen mode

Then the full prompt looks like:

function buildLayer2Prompt(emoji1: string, emoji2: string): string {
  const desc1 = EMOJI_DESCRIPTIONS[emoji1] ?? emoji1
  const desc2 = EMOJI_DESCRIPTIONS[emoji2] ?? emoji2
  return [
    `A single emoji character that fuses: [${desc1}] merged with [${desc2}].`,
    'Flat cartoon illustration style. Centered on pure white background.',
    'One single character only, no text, no multiple objects side by side.',
    'Clean vector-like look, bold outlines, vivid saturated colors.',
  ].join(' ')
}

Enter fullscreen mode Exit fullscreen mode

The "one single character only" constraint is critical. Without it, models love to render two separate objects next to each other — a cat on the left, a flame on the right — which defeats the whole point.

The Provider Chain

No single free provider is reliable enough to use alone. I set up a priority fallback chain:

T2I: Cloudflare Workers AI (flux-1-schnell)
       → ModelScope Z-Image-Turbo
         → MiniMax image-01

Enter fullscreen mode Exit fullscreen mode

Cloudflare's Workers AI gives ~230 free generations per day. For a bootstrapped side project, that's more than enough to handle organic traffic without paying anything. When it's exhausted or errors out, the request automatically falls to the next provider.

// Simplified provider selection
async function generateImage(opts: GenerateOptions): Promise<string> {
  const providers = isI2I(opts)
    ? ['gemini-proxy', 'gpt-proxy', 'modelscope-i2i', 'minimax-i2i']
    : ['cloudflare', 'modelscope-t2i', 'minimax-t2i']

  for (const provider of providers) {
    try {
      return await callProvider(provider, opts)
    } catch (err) {
      logProviderError(provider, err)
      // try next
    }
  }
  throw new Error('All providers failed')
}

Enter fullscreen mode Exit fullscreen mode

Each provider failure fires a Discord webhook alert, so I can see in real time if a provider is down.


The Transparent Background Problem

This is where most emoji tools stop. They return a white or colored background, which makes the result useless for Discord stickers, Telegram emoji, or overlay use.

I run every generated image through rembg, hosted on my own server:

async function removeBackground(imageBase64: string): Promise<string> {
  const response = await fetch(process.env.REMBG_API_URL!, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-Key': process.env.REMBG_API_KEY!,
    },
    body: JSON.stringify({ image_base64: imageBase64 }),
  })
  const { result } = await response.json()
  return result // base64 PNG with alpha channel
}

Enter fullscreen mode Exit fullscreen mode

But here's the UX problem: rembg takes 2–4 seconds. If you wait for it before showing anything, the whole generation feels slow.

Solution: Show the image immediately with the background, then swap to the transparent version once rembg finishes. The user gets visual feedback fast, and the "better" version appears a few seconds later without any loading state.

// In the API route: fire rembg async, don't await it before responding
const rembgPromise = removeBackground(rawImageBase64).catch(() => null)

// Return raw image first, rembg result comes via a separate /api/rembg call
// triggered client-side after the initial image loads

Enter fullscreen mode Exit fullscreen mode


Layer 3: Image-to-Image (Upload Your Face)

The I2I mode lets users upload a photo and fuse it with an emoji style. This is the "Genmoji" experience — without requiring an Apple device.

The challenge here is latency. I2I models take 60–120 seconds. A synchronous API call times out on Vercel (max function timeout is 300s, and 120s is cutting it close).

I solved it with a submit/poll architecture:

POST /api/generate/submit    { task_id }
GET  /api/generate/poll?id=xxx    { status: 'pending' | 'done' | 'error', result? }

Enter fullscreen mode Exit fullscreen mode

The client submits the job, gets a task_id, then polls every 3 seconds until done. The UI shows a countdown timer so users know roughly how long to wait.

For I2I, prompt engineering gets trickier. The model needs to clearly understand which elements to keep from the photo (the person's face) and which to replace with emoji style. I use a "dual prompt" strategy:

function buildLayer3DualPrompt(userEmoji: string, photoContext: string): string {
  const emojiDesc = EMOJI_DESCRIPTIONS[userEmoji] ?? userEmoji
  return [
    `Transform the person in the photo into a single emoji character.`,
    `Emoji style: ${emojiDesc}.`,
    `Keep the person's facial features and expression. Apply flat cartoon illustration style.`,
    `Result must be ONE centered emoji character. No background, no text.`,
  ].join(' ')
}

Enter fullscreen mode Exit fullscreen mode


Rate Limiting Without a Database

I didn't want to add a database just for rate limiting. Solution: IP-based limits stored in a Vercel KV-compatible in-memory map (good enough for the current traffic level, will migrate when needed):

  • 5 generations per IP per day
  • 3 generations per IP per minute (burst protection)
  • 500 total generations per day across all users
// In-memory store — resets on each Vercel function cold start
// Good enough for <1K daily users, not suitable for horizontal scaling
const ipDayMap = new Map<string, number>()
const ipMinuteMap = new Map<string, number>()
let globalDailyCount = 0

Enter fullscreen mode Exit fullscreen mode

Is this production-grade? No. But for a side project at <500 daily users, it works perfectly and avoids adding infrastructure complexity before you need it.


The Animated Emoji Feature

Static emoji are fine. Animated emoji are shareable.

I added 6 preset animations (Bounce, Float, Wiggle, Pulse, Rubber, Spin) using Canvas frame-by-frame rendering, then encoding to GIF or WebP.

The browser-side approach (gif.js) is the fallback — it works but is slow on low-end devices. The real implementation sends the PNG to my server and uses FFmpeg:

Client: PNG + animation_name + size + format
  → POST /api/animate (my rembg server also handles this)
  → FFmpeg palettegen + paletteuse with reserve_transparent=1
  → Return GIF / WebP bytes

Enter fullscreen mode Exit fullscreen mode

For transparent GIFs (critical for Discord/Telegram stickers), the FFmpeg command is:

ffmpeg -i frames_%03d.png \
  -filter_complex "[0:v] palettegen=reserve_transparent=1 [p]; [0:v][p] paletteuse=alpha_threshold=128" \
  output.gif

Enter fullscreen mode Exit fullscreen mode

Getting the transparency right took way longer than I expected. The reserve_transparent=1 + alpha_threshold=128 combination is the key — without both flags, you get either a black background or jagged edges.


What's Next

The tool is live at forgemoji.com — free to use, no account required.

Current stats after ~2 weeks:

  • 261 pre-generated combo pages for SEO long-tail
  • 3-provider T2I fallback chain (zero paid cost for up to ~230 daily generations)
  • Full animated export: 6 effects × 3 sizes × 2 formats (GIF/WebP)

Things I'm still working on:

  • AdSense monetization (applied, pending review)
  • Product Hunt launch (waiting for stable UV baseline)
  • More emoji in the mapping table (currently ~200 entries, want 500+)

If you're building something similar and ran into the same "how do I make AI output something that actually looks like an emoji" problem, I hope this helps. Happy to answer questions in the comments.