kh-tool
Version:
44 lines (43 loc) • 1.26 kB
TypeScript
declare type ImageType = "image/jpeg" | "image/png" | "image/webp";
interface ZipOptions {
/** 最长边的长度 */
max_length?: number;
/** 压缩质量 0 ~ 1 之间*/
quality?: number;
/** 图片类型 */
type?: ImageType;
}
/**
* @description 图片压缩的最核心的步骤——压缩
* @param image Image对象 dom
* @param options.max_length 设置压缩的图片的最长边
* @param options.quality 压缩质量
*/
export declare function MinImg(image: HTMLImageElement, options?: ZipOptions): Blob | File;
/**
* @description 压缩图片
* @param file 文件
* @param options 文件
* @use 读取文件方法示例
* js async写法
* ```js
* async getFile(e) {
* const file = e.target.files[0];
* let zipFile = await getZipImg(file);
* console.log(zipFile);
* }
* ```
* ts Promise链写法
* ```ts
* getFile(e: any) {
* const file = e.target.files[0];
* console.log(file); // 压缩前
* ZipImg(file, { quality: 0.1, type: "image/webp" })
* .then((resp: File | Blob) => {
* console.log(resp); // 压缩后
* })
* }
* ```
*/
export declare function ZipImg(file: File, options?: ZipOptions): Promise<Blob | File>;
export {};