/** * Center-crop an image source to a square and downscale it to a JPEG suitable * for an avatar. Avatars never render larger than ~80px, so 512px is generous * headroom while keeping the upload to a few tens of KB regardless of input. * * Pass `mirror` when capturing from a (mirrored) webcam preview so the saved * image matches what the user saw. */ export async function toAvatarBlob( source: ImageBitmap, { size = 512, mirror = false }: { size?: number; mirror?: boolean } = {}, ): Promise { if (!Number.isInteger(size) || size <= 0) { throw new Error('Avatar size must be a positive integer'); } const side = Math.min(source.width, source.height); if (side === 0) { // A not-yet-decoded