kiutils
Version:
🎑 (Library) an Javascript library that provide various utilities, including Image manipulation tools, Discord-related utilities, and a logger.
88 lines • 3.44 kB
TypeScript
/// <reference types="node" />
/**
* Supported image formats for conversion
*/
export declare enum ImageFormat {
PNG = "png",
JPEG = "jpeg",
JPG = "jpeg",
WEBP = "webp",
AVIF = "avif",
TIFF = "tiff",
GIF = "gif",
HEIF = "heif"
}
export interface ConversionOptions {
/**
* Quality of the output image (1-100), applies to lossy formats
*/
quality?: number;
/**
* Width of the output image. If only width is specified, height will be calculated to maintain aspect ratio
*/
width?: number;
/**
* Height of the output image. If only height is specified, width will be calculated to maintain aspect ratio
*/
height?: number;
/**
* Whether to fit the image within the specified dimensions (default: true)
*/
fit?: "cover" | "contain" | "fill" | "inside" | "outside";
/**
* Whether to optimize the output image (default: true)
*/
optimize?: boolean;
/**
* Whether to preserve EXIF metadata (default: false)
*/
withMetadata?: boolean;
}
/**
* Converts an image from one format to another using Sharp
* @param {string|Buffer} input - Path to the source image or image buffer
* @param {ImageFormat} format - Target format to convert to
* @param {ConversionOptions} options - Additional conversion options
* @returns {Promise<Buffer>} Converted image as buffer
* @example
* const { convertImage, ImageFormat } = require("kiutils");
*
* // Convert from file path
* convertImage("image.png", ImageFormat.WEBP)
* .then(buffer => fs.writeFileSync("image.webp", buffer));
*
* // Convert from buffer with options
* const inputBuffer = fs.readFileSync("image.jpg");
* convertImage(inputBuffer, ImageFormat.PNG, { width: 800 })
* .then(buffer => fs.writeFileSync("resized.png", buffer));
*/
export declare function convertImage(input: string | Buffer, format: ImageFormat, options?: ConversionOptions): Promise<Buffer>;
/**
* Converts an image file from one format to another and saves to a file
* @param {string} inputPath - Path to the source image
* @param {string} outputPath - Path where the converted image will be saved
* @param {ConversionOptions} options - Additional conversion options
* @returns {Promise<string>} Path to the converted image
* @example
* const { convertImageFile, ImageFormat } = require("kiutils");
*
* // Convert PNG to JPEG
* convertImageFile("image.png", "converted.jpg", { quality: 90 })
* .then(outputPath => console.log(`Converted image saved to ${outputPath}`));
*/
export declare function convertImageFile(inputPath: string, outputPath: string, options?: ConversionOptions): Promise<string>;
/**
* Creates image thumbnails quickly and efficiently
* @param {string|Buffer} input - Path to the source image or image buffer
* @param {number} width - Thumbnail width
* @param {number} height - Thumbnail height (optional, will maintain aspect ratio if omitted)
* @param {ImageFormat} format - Output format (default: png)
* @returns {Promise<Buffer>} Thumbnail image as buffer
* @example
* const { createThumbnail, ImageFormat } = require("kiutils");
*
* createThumbnail("large-image.jpg", 200)
* .then(buffer => fs.writeFileSync("thumbnail.png", buffer));
*/
export declare function createThumbnail(input: string | Buffer, width: number, height?: number, format?: ImageFormat): Promise<Buffer>;
//# sourceMappingURL=imageConverter.d.ts.map