Avatar picker also Profile picture, Photo picker

A profile picture field: a ray-avatar (the initials of display-name without a picture), Choose photo / Change photo and Remove photo, and a sheet with a ray-image-crop to frame the chosen image in a circle before it is kept. A bottom drawer on a narrow screen, a dialog otherwise. The value is the framed picture as a data URL, or a Blob with output="blob"; it takes part in a <form>.

Source on GitHub

Choose a picture, frame it in the circle, use it: the value is a small square JPEG

Choose a picture: its size shows here.

In a form, and disabled
SubmitReset
Code

API

For AI agents: this API as Markdown, or every component in llms-full.txt.

<ray-avatar-picker> · RayAvatarPicker

Choose photo opens the system picker (on a phone, the camera or the photo library); the chosen image opens in the sheet, framed in a circle, and Use photo makes the framed part, at output-size, the value. Cancel or a picture that cannot be decoded leaves the value as it was (the latter shows failed-label and fires ray-error). edit(file) opens the sheet on an image from elsewhere (a drop, a paste). Styling: the parts, and ::part(crop) for --ray-image-crop-* .

PropertyAttributeTypeDefaultDescription
namename reflectsstringForm field name. The value is submitted as a string (data URL) or, with output="blob", as a file named <name>.jpg (.png, .webp).
valuevaluestringThe picture: a URL or data URL (the value attribute: the initial picture, and what a form reset goes back to), or a Blob. null without one.
outputoutput reflectsdataurl | blobdataurlWhat Use photo makes the value: a data URL (easy to keep in JSON) or a Blob (to upload).
labellabelstringLabel above the avatar and the buttons.
descriptiondescriptionstringHelp text under the label.
errorerrorstringError message; marks the field invalid.
requiredrequired reflectsbooleanA picture is required to submit the form.
disableddisabled reflectsbooleanNo choosing, removing nor preview (also inside a disabled <fieldset>).
readonlyreadonly reflectsbooleanThe picture cannot be changed: the buttons are hidden, the preview still works. Not validated (required does not apply), as a native readonly field.
displayNamedisplay-namestringThe person's name: the avatar shows its initials without a picture (name is the form field).
acceptacceptstringimage/*File types the picker offers.
sizesize reflectsxs | sm | md | lg | xlxlSize of the avatar.
colorcolorstringColor of the avatar's initials (a palette color or any CSS color).
variantvariantlight | filled | outline | defaultlightStyle of the avatar's initials.
radiusradiusxs | sm | md | lg | xl | fullCorner radius of the avatar. Default: full (the crop frames a circle either way; the picture is square).
buttonSizebutton-sizexs | sm | md | lg | xlsmSize of the buttons.
layoutlayout reflectsstack | inlinestackThe buttons one under the other, beside the avatar, or in a row.
sheetsheet reflectsauto | drawer | dialogautoWhere the crop opens: auto is a bottom drawer on a narrow screen (up to 40em) and a dialog otherwise.
outputSizeoutput-sizestring320Side of the square picture kept, in pixels.
typetypestringimage/jpegFormat of the picture kept (PNG where the browser cannot encode it).
qualityqualitynumber0.850…1, for image/jpeg and image/webp.
maxZoommax-zoomnumber4The most zoom of the crop.
pickLabelpick-labelstringChoose photo (text avatar-picker.pick)The button without a picture.
changeLabelchange-labelstringChange photo (text avatar-picker.change)The same button with a picture.
removeLabelremove-labelstringRemove photo (text avatar-picker.remove)The button that removes the picture.
sheetLabelsheet-labelstringAdjust the photo (text avatar-picker.sheet)Title of the crop sheet.
useLabeluse-labelstringUse photo (text avatar-picker.use)The sheet's button that keeps the framed picture.
cancelLabelcancel-labelstringCancel (text avatar-picker.cancel)The sheet's button that leaves the value as it was.
cropLabelcrop-labelstringPhoto framing (text avatar-picker.crop)Accessible name of the crop area.
zoomLabelzoom-labelstringZoom (text avatar-picker.zoom)Name of the zoom slider.
previewpreview reflectsbooleanWith a picture, the avatar is a button (click, Enter, Space): it fires ray-preview and, unless that is canceled, shows the picture large in a dialog. Also with readonly; not while disabled.
previewLabelpreview-labelstringView photo (text avatar-picker.preview)Accessible name of the avatar button and title of the preview dialog.
requiredLabelrequired-labelstringPlease choose a photo. (text avatar-picker.required)Validation message of required without a picture.
failedLabelfailed-labelstringThat image could not be opened. (text avatar-picker.failed)Shown under the field when the chosen file cannot be decoded, or the framed picture encoded (until the next picture).
EventDescription
inputThe value changed (fired with change).
changeA picture was kept (Use photo) or removed. Read value.
ray-previewThe avatar was pressed (with preview and a picture). Cancelable: preventDefault() to do something else than the preview dialog (a menu, an app's own viewer).
ray-errorThe chosen file could not be decoded, or the framed picture encoded; the value is unchanged.
PartDescription
labelThe label.
descriptionThe description.
rowThe avatar and the buttons (role group, named by the label).
viewAround the avatar; a button with preview and a picture.
avatarThe ray-avatar.
actionsThe buttons' column (or row).
pickThe Choose photo / Change photo ray-button.
removeThe Remove photo ray-button.
errorThe error message.
sheetThe ray-drawer or ray-dialog of the crop.
cropThe ray-image-crop.
previewThe ray-dialog of the preview.
preview-imageThe picture in the preview dialog.
cancelThe sheet's Cancel ray-button.
useThe sheet's Use photo ray-button.

Texts

What it writes itself, in English; setStrings() translates them (Getting started: Languages).

KeyEnglish
avatar-picker.pickChoose photo
avatar-picker.changeChange photo
avatar-picker.removeRemove photo
avatar-picker.sheetAdjust the photo
avatar-picker.useUse photo
avatar-picker.cancelCancel
avatar-picker.cropPhoto framing
avatar-picker.zoomZoom
avatar-picker.previewView photo
avatar-picker.requiredPlease choose a photo.
avatar-picker.failedThat image could not be opened.