You can start using Appwrite Avatars immediately. The service is publicly accessible and does not require authentication or API keys.
Initialize the client
First, initialize the Appwrite client with your project endpoint and project ID.
import { Client, Avatars } from "appwrite";
const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');
const avatars = new Avatars(client);
Generate user initials
Generate an avatar image from a user's name or initials. This is useful for displaying user profiles when no profile picture is available.
const result = avatars.getInitials({
name: 'John Doe',
width: 200,
height: 200,
background: '000000'
});
console.log(result); // Resource URL
Generate QR code
Create a QR code from any text string. This is commonly used for two-factor authentication, sharing links, or encoding data.
const result = avatars.getQR({
text: 'https://example.com',
size: 300,
margin: 1,
download: false
});
console.log(result); // Resource URL
Get country flag
Retrieve a country flag icon by country code. This is useful for displaying user locations or regional information.
import { Flag } from "appwrite";
const result = avatars.getFlag({
code: Flag.UnitedStates,
width: 100,
height: 100
});
console.log(result); // Resource URL
Next steps
Now that you've generated your first avatars, explore more advanced features:
- Learn about user initials customization
- Discover QR code options
- Explore image manipulation capabilities