Skip to content

Next.js API to generate SVG avatars with gradient backgrounds and customizable text

Notifications You must be signed in to change notification settings

constantimi/avatar-generator

Repository files navigation

Avatar Generator API

A simple Next.js API to generate SVG avatars with gradient backgrounds and customizable text. The API supports various query parameters for personalization, making it easy to use in any project.

avatar

Features

  • Dynamically generated SVG avatars with gradients.
  • Customizable avatar size, text, and corner rounding.
  • Powered by Next.js with support for Edge API Routes.

Quick Starter

Installation

  1. Clone the repository:

    git clone https://github.com/constantimi/avatar-generator.git
    cd avatar-generator
  2. Install dependencies:

    npm install
  3. Start the development server:

    npm run dev

    The API will be available at http://localhost:3000/api/avatar.

Usage

Endpoint:

GET /api/avatar

Query Parameters:

Parameter Type Description Default
name string Name used for generating the gradient background. Random
text string Text displayed in the center of the avatar. (none)
size number Size of the avatar in pixels. 120
rounded number Corner radius for rounding the avatar in pixels. 0

Examples

  1. Simple Avatar:

    http://localhost:3000/api/avatar?name=Ex
    default
  2. Avatar with Custom Text:

    http://localhost:3000/api/avatar?name=example&text=Ex
    text
  3. Custom Size and Rounded Corners:

    http://localhost:3000/api/avatar?name=example&text=Ex&size=300&rounded=20
    text
  4. Custom Encoded Hex Colors:

    http://localhost:3000/api/avatar?size=500&from=%23123553&to=%2399CCFF

    Where %23 at the beginning is the encoding of the # symbol for the hex color.

About

Next.js API to generate SVG avatars with gradient backgrounds and customizable text

Resources

Stars

Watchers

Forks

Packages

No packages published