{
// Fetch users from your API
return [
{ id: 1, name: 'Alice', avatarId: 1 },
{ id: 2, name: 'Bob', avatarId: 2 },
{ id: 3, name: 'Charlie', avatarId: 3 },
]
}
export default async function UsersPage() {
const users = await getUsers()
return (
)
}Copy
```
--------------------------------
### Generate Avatar URLs via JavaScript
Source: https://www.loremfaces.net/docs
Helper functions to construct static or random avatar URLs dynamically.
```javascript
// Generate avatar URL
function getAvatarUrl(size, id) {
return `https://www.loremfaces.net/${size}/id/${id}.jpg`;
}
// Random avatar URL (picks a random ID 1-5)
function getRandomAvatarUrl(size) {
return getAvatarUrl(size, 1 + Math.floor(Math.random() * 5));
}
// Usage
const avatar = getAvatarUrl(96, 1);
console.log(avatar); // https://www.loremfaces.net/96/id/1.jpg
```
--------------------------------
### Generate Avatar URLs with Helper Module
Source: https://www.loremfaces.net/docs/svelte.html
A utility function to generate avatar URLs dynamically within your application logic.
```javascript
export function getAvatarUrl(size, id) {
// No ID? Pick a random face (1-5)
const faceId = id ?? 1 + Math.floor(Math.random() * 5);
return `https://www.loremfaces.net/${size}/id/${faceId}.jpg`;
}
```
--------------------------------
### Usage Without Image Optimization
Source: https://www.loremfaces.net/docs/nextjs.html
Fallback method using standard HTML img tags when next/image is not required.
```jsx
// No configuration needed for regular img tags
export function SimpleAvatar({ id = 1, size = 96 }) {
return (
// eslint-disable-next-line @next/next/no-img-element
)
}Copy
```
--------------------------------
### Implement Avatar Stack
Source: https://www.loremfaces.net/docs/svelte.html
Display a group of overlapping avatars using an each block and CSS styling.
```svelte
{#each [1, 2, 3, 4, 5] as id, index}

{/each}
```
--------------------------------
### Create reusable Avatar component
Source: https://www.loremfaces.net/docs/astro.html
Define an Astro component with props for size, ID, and random selection to standardize avatar rendering.
```astro
---
interface Props {
id?: 1 | 2 | 3 | 4 | 5;
size?: 24 | 42 | 48 | 96 | 128 | 256;
alt?: string;
random?: boolean;
}
const { id = 1, size = 96, alt = 'User avatar', random = false } = Astro.props;
// Astro components render at build/request time, so this picks a face per render
const faceId = random ? 1 + Math.floor(Math.random() * 5) : id;
const src = `https://www.loremfaces.net/${size}/id/${faceId}.jpg`;
---
```
--------------------------------
### Implement Avatar URL Service
Source: https://www.loremfaces.net/docs/angular.html
An injectable service for generating avatar URLs dynamically throughout an application.
```typescript
import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class AvatarService {
getUrl(size: number, id?: number): string {
// No ID? Pick a random face (1-5)
const faceId = id ?? 1 + Math.floor(Math.random() * 5);
return `https://www.loremfaces.net/${size}/id/${faceId}.jpg`;
}
}
```
--------------------------------
### Reference Consistent Face IDs
Source: https://www.loremfaces.net/docs
Demonstrates how the same face ID returns consistent imagery across different requested dimensions.
```text
// Same person, different sizes
https://www.loremfaces.net/24/id/1.jpg // 24x24
https://www.loremfaces.net/96/id/1.jpg // 96x96
https://www.loremfaces.net/256/id/1.jpg // 256x256
```
--------------------------------
### Embed Avatars in Markdown
Source: https://www.loremfaces.net/docs
Standard Markdown syntax for embedding images.
```markdown

```
--------------------------------
### Display Avatar Lists
Source: https://www.loremfaces.net/docs
Group multiple avatars within a container for UI lists.
```html
```
--------------------------------
### Display Avatar Stack with Control Flow
Source: https://www.loremfaces.net/docs/angular.html
Uses the Angular 17+ @for control flow to render a list of overlapping avatars.
```html
@for (id of [1, 2, 3, 4, 5]; track id; let index = $index) {
![Team member {{ id }}]()
}
```
--------------------------------
### Create Avatar Stack Component
Source: https://www.loremfaces.net/docs/vue.html
A component for displaying overlapping avatars, useful for team previews.
```vue
```
--------------------------------
### Avatar with Error Fallback
Source: https://www.loremfaces.net/docs/react.html
Handles image loading errors by displaying a placeholder UI.
```jsx
function Avatar({ id, size = 96 }) {
const [error, setError] = useState(false);
if (error) {
return (
?
);
}
return (
setError(true)}
style={{ borderRadius: '50%' }}
/>
);
}
```
--------------------------------
### Integrate with NgOptimizedImage
Source: https://www.loremfaces.net/docs/angular.html
Utilizes the NgOptimizedImage directive for improved performance and lazy loading.
```typescript
import { NgOptimizedImage } from '@angular/common';
@Component({
standalone: true,
imports: [NgOptimizedImage],
template: `
`,
})
export class ProfileComponent {}
```
--------------------------------
### Display basic avatar with img tag
Source: https://www.loremfaces.net/docs/astro.html
Use a standard HTML img tag to display a LoremFaces avatar without any additional configuration.
```html
```
--------------------------------
### Render avatar row
Source: https://www.loremfaces.net/docs/astro.html
Map over an array of IDs to generate a row of avatars for team or testimonial sections.
```astro
---
const ids = [1, 2, 3, 4, 5];
---
{ids.map((id) => (

))}
```
--------------------------------
### Generate URLs with Composable
Source: https://www.loremfaces.net/docs/vue.html
A composable function to generate avatar URLs dynamically, including usage within a component.
```typescript
export function useLoremFaces() {
const getUrl = (
size: 24 | 42 | 48 | 96 | 128 | 256,
id?: 1 | 2 | 3 | 4 | 5
): string => {
// No ID? Pick a random face (1-5)
const faceId = id ?? 1 + Math.floor(Math.random() * 5)
return `https://www.loremfaces.net/${size}/id/${faceId}.jpg`
}
const sizes = [24, 42, 48, 96, 128, 256] as const
const ids = [1, 2, 3, 4, 5] as const
return { getUrl, sizes, ids }
}
// Usage in component
```
--------------------------------
### Avatar Stack with Tailwind
Source: https://www.loremfaces.net/docs/nextjs.html
Creates a stacked avatar UI component using Tailwind CSS for spacing.
```tsx
import Image from 'next/image'
interface AvatarStackProps {
count?: number
size?: number
}
export function AvatarStack({ count = 5, size = 48 }: AvatarStackProps) {
const avatars = Array.from(
{ length: Math.min(count, 5) },
(_, i) => i + 1
)
return (
{avatars.map(id => (
))}
)
}Copy
```
--------------------------------
### Avatar with Styled Components
Source: https://www.loremfaces.net/docs/react.html
Integrates LoremFaces with the styled-components library for custom styling.
```tsx
import styled from 'styled-components';
const StyledAvatar = styled.img<{ size: number }>`
width: ${props => props.size}px;
height: ${props => props.size}px;
border-radius: 50%;
object-fit: cover;
border: 2px solid white;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
`;
function Avatar({ id = 1, size = 96 }) {
return (
);
}
```
--------------------------------
### Apply CSS Background Avatars
Source: https://www.loremfaces.net/docs
Use CSS background properties to style elements with avatar images.
```css
.user-avatar {
width: 96px;
height: 96px;
border-radius: 50%;
background-image: url('https://www.loremfaces.net/96/id/1.jpg');
background-size: cover;
}
```
--------------------------------
### Create Reusable Avatar Component
Source: https://www.loremfaces.net/docs/nextjs.html
A flexible Avatar component supporting custom sizes, IDs, and random face selection.
```tsx
import Image from 'next/image'
type Size = 24 | 42 | 48 | 96 | 128 | 256
type FaceId = 1 | 2 | 3 | 4 | 5
interface AvatarProps {
id?: FaceId
size?: Size
alt?: string
random?: boolean
priority?: boolean
className?: string
}
export function Avatar({
id = 1,
size = 96,
alt = 'User avatar',
random = false,
priority = false,
className = '',
}: AvatarProps) {
// random picks one of the 5 faces at render time
const faceId = random ? 1 + Math.floor(Math.random() * 5) : id
const src = `https://www.loremfaces.net/${size}/id/${faceId}.jpg`
return (
)
}
// Usage in App Router
import { Avatar } from '@/components/avatar'
export default function Page() {
return (
)
}Copy
```
--------------------------------
### Create Reusable Avatar Component
Source: https://www.loremfaces.net/docs/svelte.html
A Svelte 5 component using $props and $derived for dynamic size, ID, and random face selection.
```svelte
```
--------------------------------
### Add Accessible Alt Text
Source: https://www.loremfaces.net/docs
Include descriptive alt text for screen readers when using image tags.
```html
```
--------------------------------
### Create Reusable Avatar Component
Source: https://www.loremfaces.net/docs/vue.html
A flexible Vue 3 component supporting size, ID, and random face selection props.
```vue
```
--------------------------------
### Create Reusable Avatar Component
Source: https://www.loremfaces.net/docs/angular.html
A standalone component for Angular 15+ that supports configurable sizes, IDs, and random face selection.
```typescript
import { Component, Input } from '@angular/core';
type Size = 24 | 42 | 48 | 96 | 128 | 256;
type FaceId = 1 | 2 | 3 | 4 | 5;
@Component({
selector: 'app-avatar',
standalone: true,
template: `
`,
})
export class AvatarComponent {
@Input() id: FaceId = 1;
@Input() size: Size = 96;
@Input() alt = 'User avatar';
@Input() random = false;
// Picked once per component instance, so the face stays stable
private randomId = 1 + Math.floor(Math.random() * 5);
get src(): string {
const faceId = this.random ? this.randomId : this.id;
return `https://www.loremfaces.net/${this.size}/id/${faceId}.jpg`;
}
}
```
--------------------------------
### Reusable Avatar Component
Source: https://www.loremfaces.net/docs/react.html
A flexible component supporting size, ID, and random selection props. The random prop ensures the face remains stable across re-renders.
```tsx
interface AvatarProps {
id?: 1 | 2 | 3 | 4 | 5;
size?: 24 | 42 | 48 | 96 | 128 | 256;
alt?: string;
className?: string;
random?: boolean;
}
function Avatar({
id = 1,
size = 96,
alt = "User avatar",
className,
random = false
}: AvatarProps) {
// Random picks an ID once, so the face stays stable across re-renders
const [randomId] = useState(() => 1 + Math.floor(Math.random() * 5));
const src = `https://www.loremfaces.net/${size}/id/${random ? randomId : id}.jpg`;
return (
);
}
// Usage
```
--------------------------------
### Custom Avatar Hook
Source: https://www.loremfaces.net/docs/react.html
A hook for programmatically generating avatar URLs, useful for lists or dynamic data.
```tsx
function useLoremFaces() {
const getUrl = (
size: 24 | 42 | 48 | 96 | 128 | 256,
id?: 1 | 2 | 3 | 4 | 5
) => {
// No ID? Pick a random face (1-5)
const faceId = id ?? 1 + Math.floor(Math.random() * 5);
return `https://www.loremfaces.net/${size}/id/${faceId}.jpg`;
};
return { getUrl };
}
// Usage
function UserList() {
const { getUrl } = useLoremFaces();
return (
{[1, 2, 3, 4, 5].map(id => (

))}
);
}
```
--------------------------------
### Avatar Stack Component
Source: https://www.loremfaces.net/docs/react.html
Displays a group of overlapping avatars, commonly used for team previews.
```jsx
function AvatarStack({
count = 5,
size = 48
}: { count?: number; size?: number }) {
return (
{Array.from({ length: Math.min(count, 5) }, (_, i) => (

))}
);
}
// Usage
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.