# Avatar Upload

> A profile photo field with a real cropper. Drop an image on the avatar or browse, then frame it in a round mask: drag or arrow keys to move, slider, wheel or +/− to zoom, quarter-turn rotate, a thirds grid while dragging. Saves a square JPEG from a canvas, checks type and size up front, Adjust reframes the original rather than the crop, and Remove falls back to initials.

- Slug: `avatar-upload`
- Category: [Forms](https://www.assembli.design/category/forms.md)
- Type: component
- Tags: avatar, upload, crop, image, profile, photo, settings, drag-and-drop
- npm dependencies: lucide-react
- shadcn/ui dependencies: none
- Live preview: https://www.assembli.design/preview/avatar-upload
- Page: https://www.assembli.design/components/avatar-upload

![Avatar Upload preview](https://www.assembli.design/thumbnails/avatar-upload-light.png)

## Props

Other props pass through to the root element.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string \| null` |  | The current photo URL (controlled). `null` means no photo. |
| `defaultValue` | `string \| null` | `null` |  |
| `onChange` | `(file: Blob \| null, url: string \| null) => void` |  | Called with the cropped image and an object URL for it, or with nulls when the photo is removed. |
| `name` | `string` |  | Used for the initials shown when there's no photo. |
| `maxSize` | `number` | `5 * 1024 * 1024` | Largest accepted file, in bytes. Defaults to 5 MB. |
| `outputSize` | `number` | `512` | Width and height of the exported image, in px. |
| `defaultEditing` | `boolean` |  | Open the cropper on the current photo at mount. |
| `label` | `React.ReactNode` | `"Profile photo"` |  |
| `description` | `React.ReactNode` | `"JPG, PNG or WebP, up to 5 MB."` |  |

## Install

One-time setup (needs a subscription):

1. Add the registry to the project's `components.json`: `{"@assembli":{"url":"https://www.assembli.design/r/{name}.json","headers":{"Authorization":"Bearer ${ASSEMBLI_API_KEY}"}}}` (merge into `"registries"`).
2. Put an API key from https://www.assembli.design/account in `.env.local` as `ASSEMBLI_API_KEY=asm_…`.

Then install with the shadcn CLI (writes `components/avatar-upload/avatar-upload.tsx` and installs dependencies):

```bash
npx shadcn@latest add @assembli/avatar-upload
```

Registry item JSON: https://www.assembli.design/r/avatar-upload.json (send `Authorization: Bearer <api key>`)

## Code

> Component source needs an Assembli subscription ($12/month or $96/year) and an API key sent as `Authorization: Bearer <key>`. To get one without copying anything, POST https://www.assembli.design/api/agent/login (or call the MCP tool connect_account), show the user the link it returns, and poll https://www.assembli.design/api/agent/token for the key. Or subscribe at https://www.assembli.design/pricing and create a key at https://www.assembli.design/account.
