processImage crops, resizes and converts an image with no editor on screen.
crop, or the largest centered window of aspectRatio) at targetSize, with the same output rules as Save, so never more than 16.7 MP.
Parameters
string | File | Blob | ArrayBuffer | Uint8Array | HTMLImageElement | HTMLCanvasElement | ImageBitmap
required
The image. It takes everything the editor’s
src prop takes, except null: a URL (http(s):, data:, blob:), a File or Blob, its bytes, an <img>, a canvas or an ImageBitmap.Options
Every option is optional. An option it can’t take rejects withINVALID_PROPS before anything loads.
number | null
With no
crop, the ratio (width / height, above 0) of the crop: its largest centered window. null or absent: the whole image. With a crop, it only decides whether the returned state keeps a ratio: it does when crop already has this ratio, and opens free otherwise.Rect
The crop,
{ x, y, width, height }, in the file’s own px. It is held inside the image: one past an edge moves in, one larger than the image shrinks at its ratio.Size
default:"the crop's own size"
The box the crop is drawn into,
{ width, height }, in output px, at the crop’s ratio. It may enlarge a small crop. The output never passes 16,777,216 px (2^24), whatever is asked.number
The output’s largest width, in px (1 or more). The ratio is kept, and it never enlarges the image.
number
The output’s largest height, in px (1 or more). The ratio is kept, and it never enlarges the image.
'image/jpeg' | 'image/png' | 'image/webp'
default:"the source's"
The type written: the source’s when it is one of these, a PNG otherwise.
number
default:"90"
The JPEG and WebP quality, 0 to 100.
EmbedEditorWatermark | null
default:"null"
Full edition. The host’s watermark, drawn at its own values. A fixed or required one that can’t load rejects with
MARK_FAILED; a free one is left out. See Props.EmbedEditorSignature | null
default:"null"
Full edition. The host’s signature, drawn at its own values. A fixed or required one that can’t load rejects with
MARK_FAILED; a free one is left out.Returns
A promise that resolves to the file and the state it was made with, or rejects with an EmbedEditorError:INVALID_PROPS, LOAD_FAILED, UNSUPPORTED_FORMAT, MARK_FAILED or EXPORT_FAILED.
File
The processed image.
EditState
The edits it was made with, ready for the editor’s
state prop. Given both crop and aspectRatio, it keeps aspectRatio only when crop already has that ratio, so reopening it never refits the crop. See EditState.Units
A photo over 16.7 MP is worked at a smaller copy, so the units differ:cropis in the file’s own px, and lands on the same region of the copy.- The
stateit resolves to is in the copy’s px, ready for the editor’sstateprop.
Example
thumbnail.ts