Creates an instance of AioImageProcessor. Initializes the image processor with default settings and resolves the template directory path.
Optional
filepath: stringOptional. The initial filepath for the image to be processed.
Protected
_rootPrivate
_settingsPrivate
_Gets the current metadata settings.
Sets the metadata for the image processor. Merges the provided metadata with the existing metadata.
The new metadata to apply.
Gets the current settings of the image processor.
Sets the settings for the image processor. Merges the provided settings with the existing settings.
The new settings to apply.
Gets the current watermark settings.
Sets the watermark settings for the image processor. Merges the provided watermark settings with the existing watermark settings.
The new watermark settings to apply.
Private
_buildPrivate
Builds the output path for the converted image.
The output path or format. If only format is provided, the output will be in the same directory as the source.
The suffix to add to the output filename.
Protected
_getProtected
_getPrivate
_resizeResizes the image based on the maximum width, maintaining aspect ratio.
The maximum width for the resized image.
The metadata containing the original width and height.
Private
_setSets the EXIF metadata for an image. This function takes image metadata and formats it into an EXIF-compatible structure. It supports setting fields like ImageDescription, Artist, Copyright, and more.
The metadata to set, including description, author, copyright, origin, and keywords.
Private
_setSets the source image file for processing. This method initializes the image processing pipeline by setting the source file path and validating its format.
The path to the source image file.
Protected
isChecks if a directory exists. If it doesn't, it creates the directory and any necessary parent directories.
The path of the directory to check or create.
Reads a file line by line and returns an array of strings, where each string is a line from the file.
This method opens a file, reads it line by line, and stores each line as a separate string in an array. It uses an asynchronous iterator to efficiently handle large files without loading the entire content into memory at once.
The path to the file to be scanned.
Searches for files within a specified directory, optionally filtering by file extension.
This method recursively scans a directory and its subdirectories for files. It can filter the results based on a specified file extension or an array of extensions. If no extension is provided, it returns all files. It also has an option to include directories in the results.
The path to the directory to search.
A single file extension or an array of file extensions to filter by. If undefined, no extension filtering is applied.
Optional
showDir: boolean = falseIf true, directories will be included in the results. Defaults to false.
const fileOp = new AioFileOperation();
// Search for all .txt files in the 'mydir' directory
const txtFiles = await fileOp.search('mydir', '.txt');
// Search for all .txt and .md files in the 'mydir' directory
const txtAndMdFiles = await fileOp.search('mydir', ['.txt', '.md']);
// Search for all files and directories in the 'mydir' directory
const allFilesAndDirs = await fileOp.search('mydir', undefined, true);
Converts the image to the specified format and applies various options.
The output path or the desired format (e.g., 'jpg', 'png'). If only format is provided, the output will be in the same directory as the source.
Options for image processing, including format-specific options, resizing, watermark, etc.
AioImageProcessor
The
AioImageProcessor
class is a powerful tool for manipulating and processing images. It allows you to resize, convert, add watermarks, and set metadata for images. This class extendsAioFileOperation
, providing a robust foundation for file-related operations.Features
Installation
Usage
Basic Usage
Setting Custom Settings
Setting Metadata
Setting Watermark