Constructor
new ImageProcessor(optionsopt)
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Properties
|
- Source:
Members
_webpSupported :boolean|null
Cached WebP support detection result
Type:
- boolean | null
- Source:
Methods
_canvasToBlob(canvas, format, quality) → {Promise.<(Blob|null)>}
Convert a canvas to a Blob with the given format and quality.
Parameters:
| Name | Type | Description |
|---|---|---|
canvas |
HTMLCanvasElement | |
format |
string | MIME type |
quality |
number | 0-1 |
- Source:
Returns:
- Type
- Promise.<(Blob|null)>
(async) _processSource(source, opts) → {Promise.<({blob: Blob, width: number, height: number, originalSize: number, compressedSize: number, format: string}|null)>}
Core processing pipeline: resize → compress → enforce byte budget.
Parameters:
| Name | Type | Description |
|---|---|---|
source |
ImageBitmap | HTMLImageElement | |
opts |
Object |
- Source:
Returns:
- Type
- Promise.<({blob: Blob, width: number, height: number, originalSize: number, compressedSize: number, format: string}|null)>
createPreview(blob) → {string|null}
Create an object URL preview from a Blob. Caller must revoke.
Parameters:
| Name | Type | Description |
|---|---|---|
blob |
Blob |
- Source:
Returns:
Object URL or null
- Type
- string | null
estimateStorage(blob) → {number}
Estimate storage bytes for a blob (actual blob.size).
Parameters:
| Name | Type | Description |
|---|---|---|
blob |
Blob |
- Source:
Returns:
- Type
- number
(async) processFile(file, optsopt) → {Promise.<({blob: Blob, width: number, height: number, originalSize: number, compressedSize: number, format: string}|null)>}
Process a File or Blob into a compressed, resized image.
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
file |
File | Blob | Input image file |
|||||||||||||||||
opts |
Object |
<optional> |
Override options for this call Properties
|
- Source:
Returns:
- Type
- Promise.<({blob: Blob, width: number, height: number, originalSize: number, compressedSize: number, format: string}|null)>
(async) processFromUrl(url, optsopt) → {Promise.<({blob: Blob, width: number, height: number, originalSize: number, compressedSize: number, format: string}|null)>}
Process an image from a URL into a compressed, resized blob.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
url |
string | Image URL to fetch and process |
|
opts |
Object |
<optional> |
Override options |
- Source:
Returns:
- Type
- Promise.<({blob: Blob, width: number, height: number, originalSize: number, compressedSize: number, format: string}|null)>
(async) supportsWebP() → {Promise.<boolean>}
Detect whether the browser supports WebP encoding via Canvas. Result is cached after first call.
- Source:
Returns:
- Type
- Promise.<boolean>