import { Buffer } from 'node:buffer'; import type { PhotonImage as PhotonImageType } from '@silvia-odwyer/photon'; import type { Rect, Size } from '../types'; /** * Saves a Base64-encoded image to a file * * @param options - An object containing the Base64-encoded image data and the output file path * @param options.base64Data - The Base64-encoded image data * @param options.outputPath - The path where the image will be saved * @throws Error if there is an error during the saving process */ export declare function saveBase64Image(options: { base64Data: string; outputPath: string; }): Promise; /** * Resizes an image buffer. * * This API preserves the original bytes and format when the requested * dimensions are unchanged. When dimensions change, it returns JPEG. Callers * must inspect the returned `format` instead of assuming an output format. */ export declare function resizeAndConvertImgBuffer(inputFormat: string, inputData: Buffer, newSize: Size): Promise<{ buffer: Buffer; /** The actual encoded format of `buffer`, such as `png` or `jpeg`. */ format: string; }>; export declare const normalizeBase64Body: (body: string) => string; /** Convert an image buffer to JPEG without changing its dimensions. */ export declare function convertImgBufferToJpeg(inputData: Buffer, quality?: number): Promise; export declare const inferBase64ImageFormat: (base64Body: string) => "jpeg" | "png"; export declare const createImgBase64ByFormat: (format: string, body: string) => string; export interface NormalizeScreenshotBase64Options { label?: string; } export declare const normalizeScreenshotBase64: (base64: string, options?: NormalizeScreenshotBase64Options) => string; export declare const normalizeBase64Image: (base64: string) => string; export type JpegBase64DataUrl = `data:image/jpeg;base64,${string}`; export interface ResizeBase64ImageToJpegOptions { /** * Expected input dimensions in positive integer pixels. When provided, they * are checked against the encoded image header before processing. */ sourceSize?: Size; /** Exact output dimensions in positive integer pixels. */ targetSize: Size; /** JPEG quality used only when encoding is required. Defaults to 90. */ jpegQuality?: number; } export interface ConstrainBase64ImageToMaxSizeOptions { /** Maximum allowed width or height in positive integer pixels. */ maxSize: number; /** JPEG quality used when resizing is required. Defaults to 90. */ jpegQuality?: number; } /** * Ensures that a PNG/JPEG Base64 image is represented as JPEG without resizing. * Existing JPEG bytes are reused; PNG input is encoded with `jpegQuality`. * This function does not read image dimensions. * * @param inputBase64 - A PNG/JPEG data URL or raw Base64 image body. * @param jpegQuality - JPEG quality from 1 to 100 when encoding PNG. Defaults to 90. * @returns A JPEG data URL with unchanged dimensions. */ export declare function convertBase64ImageToJpeg(inputBase64: string, jpegQuality?: number): Promise; /** * Resizes a PNG/JPEG Base64 image and ensures that the result is JPEG. * * An unchanged JPEG is returned without re-encoding. An unchanged PNG is * converted to JPEG, while a size change performs resize and JPEG encoding. * `jpegQuality` applies only when encoding is required. * * @param inputBase64 - A PNG/JPEG data URL or raw Base64 image body. * @param options - Source dimensions, target dimensions, and JPEG quality. * @returns A JPEG data URL with the requested dimensions. */ export declare function resizeBase64ImageToJpeg(inputBase64: string, options: ResizeBase64ImageToJpegOptions): Promise; /** * Constrains a PNG/JPEG Base64 image to a maximum width or height while * preserving its aspect ratio. * * Images already within the bound are returned unchanged, including their * original format. Oversized images are parsed once, resized, and encoded as * JPEG. * * @param inputBase64 - A PNG/JPEG data URL or raw Base64 image body. * @param options - Maximum dimension and optional JPEG quality. * @returns The original image when already bounded, otherwise a JPEG data URL. */ export declare function constrainBase64ImageToMaxSize(inputBase64: string, options: ConstrainBase64ImageToMaxSizeOptions): Promise; /** * @deprecated Use `resizeBase64ImageToJpeg` when JPEG output is required. * This API retains its historical behavior: unchanged dimensions preserve the * input format, while resized output is encoded as JPEG. */ export declare function resizeImgBase64(inputBase64: string, newSize: { width: number; height: number; }): Promise; /** * Calculates new dimensions for an image while maintaining its aspect ratio. * * This function is designed to resize an image to fit within a specified maximum width and height * while maintaining the original aspect ratio. If the original width or height exceeds the maximum * dimensions, the image will be scaled down to fit. * * @param {number} originalWidth - The original width of the image. * @param {number} originalHeight - The original height of the image. * @returns {Object} An object containing the new width and height. * @throws {Error} Throws an error if the width or height is not a positive number. */ export declare function zoomForGPT4o(originalWidth: number, originalHeight: number): { width: number; height: number; }; export declare function photonFromBase64(base64: string): Promise; export declare function paddingToMatchBlock(image: PhotonImageType, blockSize?: number): Promise<{ width: number; height: number; image: PhotonImageType; }>; export declare function paddingToMatchBlockByBase64(imageBase64: string, blockSize?: number): Promise<{ width: number; height: number; imageBase64: string; }>; export declare function cropByRect(imageBase64: string, rect: Rect): Promise<{ width: number; height: number; imageBase64: string; }>; export declare function photonToBase64(image: PhotonImageType, quality?: number): Promise; export declare const httpImg2Base64: (url: string) => Promise; /** * Convert image file to base64 string * Because this method is synchronous, the npm package `sharp` cannot be used to detect the file type. * TODO: convert to webp to reduce base64 size. */ export declare const localImg2Base64: (imgPath: string, withoutHeader?: boolean) => string; /** * PreProcess image url to ensure image is accessible to LLM. * @param url - The url of the image, it can be a http url or a base64 string or a file path * @param convertHttpImage2Base64 - Whether to convert http image to base64, if true, the http image will be converted to base64, otherwise, the http image will be returned as is * @returns The base64 string of the image (when convertHttpImage2Base64 is true or url is a file path) or the http image url */ export declare const preProcessImageUrl: (url: string, convertHttpImage2Base64: boolean) => Promise; /** * parse base64 string to get mimeType and body */ export declare const parseBase64: (fullBase64String: string) => { mimeType: string; body: string; }; /** * Scales an image by a specified factor using Sharp or Photon * @param imageBase64 - Base64 encoded image * @param scale - Scale factor (e.g., 2 for 2x, 1.5 for 1.5x) * @returns Scaled image with new dimensions */ export declare function scaleImage(imageBase64: string, scale: number): Promise<{ width: number; height: number; imageBase64: string; }>; /** Pad the right and bottom edges with white without changing content coordinates. */ export declare function padBase64ImageToMinimumSize(imageBase64: string, minimum: number): Promise<{ imageBase64: string; width: number; height: number; }>; //# sourceMappingURL=transform.d.ts.map