Constructor
new ImageProcessor(sharpInstance)
- Description:
- Creates a new ImageProcessor instance.
Parameters:
Name | Type | Description |
---|---|---|
sharpInstance |
An instance of the sharp image processing library. |
Methods
blur(sigma) → {ImageProcessor}
- Description:
- Applies a blur effect to the image.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.blur(5);
Parameters:
Name | Type | Description |
---|---|---|
sigma |
number | The blur amount (higher values = more blur). |
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
composite(watermarkBuffer, options) → {ImageProcessor}
- Description:
- Composites another image onto this one.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.composite(watermarkBuffer, { left: 10, top: 10, opacity: 0.5 });
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
watermarkBuffer |
Buffer | The image buffer to composite. | ||||||||||||||||||||
options |
object | The options for compositing.
Properties
|
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
flip() → {ImageProcessor}
- Description:
- Flips the image horizontally.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.flip();
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
flop() → {ImageProcessor}
- Description:
- Flips the image vertically.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.flop();
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
format(format, optionsopt) → {ImageProcessor}
- Description:
- Converts the image to a specific format.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.format('jpeg', { quality: 80 });
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
format |
string | The format to convert to (e.g., 'jpeg', 'png', 'webp'). | |
options |
object |
<optional> |
Options for the format conversion (see sharp documentation). |
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
greyscale() → {ImageProcessor}
- Description:
- Converts the image to greyscale.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.greyscale();
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
resize(options) → {ImageProcessor}
- Description:
- Resizes the image to the specified dimensions.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.resize({ width: 200, height: 200, fit: 'contain', background: '#FFFFFF' });
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | The resize options.
Properties
|
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
rotate(angle) → {ImageProcessor}
- Description:
- Rotates the image by the specified angle.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.rotate(90);
Parameters:
Name | Type | Default | Description |
---|---|---|---|
angle |
number |
0
|
The angle to rotate the image (in degrees). |
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
sharpen() → {ImageProcessor}
- Description:
- Sharpens the image.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.sharpen();
Returns:
The ImageProcessor instance for chaining.
- Type
- ImageProcessor
(async) toBuffer() → {Promise.<Buffer>}
- Description:
- Processes the image and returns the final data as a Buffer.
Example
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.resize({ width: 200, height: 200 });
const buffer = await processor.toBuffer();
Returns:
- Type
- Promise.<Buffer>
(async) toFile(scope, filePath) → {Promise.<void>}
- Description:
- Processes the image and saves it to a file using our secure fs module.
Example
// path with leading slash indicates path from scope root,
// path without leading slash indicates path relative to the executing script
// here image is loaded from <project>/<app_name>/<box>/images/gingee.png
// image is and saved to <project>/<app_name>/output/processed_image.webp
const processor = image.load(fs.BOX, '/images/gingee.png');
processor.resize({ width: 200, height: 200 });
await processor.toFile(fs.WEB, '/output/processed_image.webp');
Parameters:
Name | Type | Description |
---|---|---|
scope |
string | The scope to save to (fs.BOX or fs.WEB). |
filePath |
string | The destination file path. |
Returns:
- Type
- Promise.<void>