zpl-image-modern
Version:
Modern ZPL image conversion library supporting both browser and Node.js environments
79 lines • 2.52 kB
TypeScript
/**
* 图像旋转选项
* N: No rotation (default)
* R: Rotate 90 degrees clockwise
* L: Rotate 90 degrees counter-clockwise
* I: Rotate 180 degrees (inverted)
* B: Same as 'L'
*/
export type ZplRotation = "N" | "R" | "L" | "I" | "B";
/**
* 图像转换的配置选项
*/
export interface ZplImageOptions {
/** 黑色阈值百分比 (1-99),默认 50 */
black?: number;
/** 图像旋转选项 */
rotate?: ZplRotation;
/** 如果为 true,则不裁剪图像周围的空白区域 */
notrim?: boolean;
}
/**
* ZPL 图像转换结果
*/
export interface ZplImageResult {
/** 未压缩数据的字节长度 */
length: number;
/** 每行压缩后的字节数 */
rowlen: number;
/** (旋转后) 图像宽度,单位:像素 */
width: number;
/** (旋转后) 图像高度,单位:像素 */
height: number;
/** Z64 压缩格式的 ZPL 字符串 */
z64?: string;
/** ACS 压缩格式的 ZPL 字符串 */
acs?: string;
}
/**
* 压缩库接口
*/
export interface CompressionAdapter {
deflate: (data: Uint8Array) => Uint8Array;
toBase64: (data: Uint8Array) => string;
}
/**
* 带有尺寸信息的 Uint8Array
* @internal
*/
interface SizedUint8Array extends Uint8Array {
width: number;
height: number;
}
/**
* 核心处理逻辑,将 RGBA 数据转换为 ZPL 图像数据
* @param rgba - 图像的 RGBA 像素数据
* @param width - 原始图像宽度
* @param opts - 配置选项
* @returns 包含 ZPL 数据的对象
*/
export declare function processRgba(rgba: Uint8ClampedArray | Buffer, width: number, opts?: ZplImageOptions): SizedUint8Array;
/**
* 将 RGBA 像素数据转换为 Z64 压缩格式的 ZPL。
* @param rgba - Uint8ClampedArray (来自 Canvas) 或 Buffer (来自 Node.js)
* @param width - 图像宽度
* @param compression - 压缩适配器
* @param opts - 配置选项
* @returns 包含 ZPL 数据的对象
*/
export declare function rgbaToZ64(rgba: Uint8ClampedArray | Buffer, width: number, compression: CompressionAdapter, opts?: ZplImageOptions): ZplImageResult;
/**
* 将 RGBA 像素数据转换为 ACS 压缩格式的 ZPL。
* @param rgba - Uint8ClampedArray (来自 Canvas) 或 Buffer (来自 Node.js)
* @param width - 图像宽度
* @param opts - 配置选项
* @returns 包含 ZPL 数据的对象
*/
export declare function rgbaToACS(rgba: Uint8ClampedArray | Buffer, width: number, opts?: ZplImageOptions): ZplImageResult;
export {};
//# sourceMappingURL=core.d.ts.map