A module for image processing using the Sharp library.
It provides a simple and secure way to manipulate images, including resizing, rotating, flipping, and more.
NOTE: path with leading slash indicates path from scope root, path without leading slash indicates path relative to the executing script
IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.
- Description:
- A module for image processing using the Sharp library. It provides a simple and secure way to manipulate images, including resizing, rotating, flipping, and more. NOTE: path with leading slash indicates path from scope root, path without leading slash indicates path relative to the executing script IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.
Classes
Methods
(static) loadFromBuffer(buffer) → {ImageProcessor}
- Description:
- Loads an image from a Buffer. This function initializes an ImageProcessor instance with the provided image data.
Example
const image = require('image');
const processor = image.loadFromBuffer(buffer);
processor.resize({ width: 200, height: 200 }).greyscale().toFile(fs.WEB, 'output/processed_image.webp');
Parameters:
Name | Type | Description |
---|---|---|
buffer |
Buffer | A Buffer containing image data. |
Throws:
-
If the input is not a Buffer.
- Type
- Error
Returns:
A new instance of our ImageProcessor for chaining operations.
- Type
- ImageProcessor
(static) loadFromFile(filePath) → {ImageProcessor}
- Description:
- Loads an image from a Buffer or a file path. This function initializes an ImageProcessor instance with the provided image data. It supports both Buffer inputs (for in-memory images) and file paths (for images stored on disk). It abstracts the complexities of loading images, providing a simple interface for developers to work with images. It allows for flexible image processing workflows, enabling developers to chain multiple operations on the image.
Example
const image = require('image');
const processor = image.load(fs.BOX, './images/gingee.png');
processor.resize({ width: 200, height: 200 }).greyscale().toFile(fs.WEB, 'output/processed_image.webp');
Parameters:
Name | Type | Description |
---|---|---|
filePath |
string | a file path to an image file. |
Throws:
-
If the input is not a Buffer or a valid file path.
- Type
- Error
Returns:
A new instance of our ImageProcessor for chaining operations.
- Type
- ImageProcessor