For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/image-picker.md.

LynxImagePicker

Lets someone pick a photo with the phone's photo picker and hands it back as a Blob. import { LynxImagePicker, ImagePickerError, type ImagePickerOptions, type ImagePickerErrorCode, type PickedImage } from '@blotch/angular-lynx';

Pick a Photo shows it in use.

Usage

const picker = inject(LynxImagePicker);

const picked = await picker.pick({ maxDimension: 1024, quality: 0.85 });
if (picked) {
  await uploadBytes(storageRef, picked.blob, { contentType: picked.type });
}

API

LynxImagePicker

@Injectable({ providedIn: 'root' })
class LynxImagePicker {}

Uses PHPickerViewController on iOS, the Photo Picker on Android, and an <input type="file" accept="image/*"> in the web preview. Only the apps --platform builds, with ng build or ng serve, have the native module behind it; elsewhere, such as Lynx Explorer and unit tests, pick() rejects with unavailable.

LynxImagePicker.pick()

pick(options?: ImagePickerOptions): Promise<PickedImage | null>;

Opens the picker and resolves with the photo picked, or with null when the person closes the picker without choosing. Rejects with an ImagePickerError, or with a RangeError for an option out of range. One picker can be open at a time: on iOS and Android, picking again while one is open rejects with failed; in the web preview, it resolves the open pick with null.

ImagePickerOptions

type ImagePickerOptions = {
  readonly maxDimension?: number;
  readonly quality?: number;
};
OptionDescription
maxDimensionScales the photo down, if it's larger, so its longest side has at most this many pixels, at least 1. It's never scaled up
qualityThe JPEG quality of the re-encoded photo, from 0 to 1. Defaults to 0.9

Either option re-encodes the photo as a JPEG: upright, whichever way the camera stored it, without the original's metadata, and with a white background where it was transparent. Without them, a JPEG, PNG, GIF or WebP comes back as it was picked, and any other format, such as HEIC, is re-encoded as a JPEG at full size.

PickedImage

type PickedImage = {
  readonly blob: Blob;
  readonly name: string;
  readonly type: string;
};
PropertyDescription
blobThe photo's bytes
nameA file name for it, such as IMG_0042.jpg, whose extension matches type. On Android it's the photo's number in the library, such as 1000000020.jpg: the Photo Picker doesn't share the file's own name
typeIts MIME type, such as image/jpeg: the same as blob.type

ImagePickerError

class ImagePickerError extends Error {
  readonly code: ImagePickerErrorCode;
}

type ImagePickerErrorCode = 'unavailable' | 'failed';
codeWhen
unavailableThe host has no photo picker
failedThe picker couldn't open, one was already open, or the picked photo couldn't be read or decoded