@egova-mobile/app-media-utils 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ import { WatermarkOptions } from './watermark';
2
+ export declare class ResizeOptions {
3
+ maxSideLength: number;
4
+ constructor(maxSideLength: number);
5
+ }
6
+ export declare class CompressOptions {
7
+ photoFileSizeLimit: number;
8
+ constructor(photoFileSizeLimit: number);
9
+ }
10
+ export declare class ImageProcessor {
11
+ private file;
12
+ private resizeOptions;
13
+ private watermarkOptions;
14
+ private compressOptions;
15
+ constructor(file: File, resizeOptions: ResizeOptions, watermarkOptions: WatermarkOptions, compressOptions: CompressOptions);
16
+ process(): Promise<void | File>;
17
+ compress(canvas: HTMLCanvasElement, filename: string, lastModified: number, type: string, quality: number): Promise<File>;
18
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Convert File to data schema url
3
+ * @param file
4
+ */
5
+ export declare function file2DataURL(file: File): Promise<string>;
6
+ /**
7
+ * Convert file to image
8
+ * @param file
9
+ */
10
+ export declare function file2Image(file: File): Promise<HTMLImageElement>;
11
+ export declare function image2file(img: HTMLImageElement, fileName: string, lastModified: number, type?: string, quality?: number): Promise<File>;
12
+ /**
13
+ * Draw image on canvas
14
+ * @param img
15
+ * @param width
16
+ * @param height
17
+ */
18
+ export declare function image2Canvas(img: HTMLImageElement, type: string, width?: number, height?: number): Promise<HTMLCanvasElement>;
19
+ /**
20
+ * Export Image from canvas
21
+ * @param canvas
22
+ * @param type
23
+ * @param quality
24
+ * @see {@link https://meshworld.in/convert-canvas-to-an-image-using-javascript/}
25
+ */
26
+ export declare function canvas2Image(canvas: HTMLCanvasElement, type?: string, quality?: number): Promise<HTMLImageElement>;
27
+ /**
28
+ * Export File from canvas
29
+ * @param canvas
30
+ * @param fileName
31
+ * @param lastModified
32
+ * @param type
33
+ * @param quality
34
+ * @see {@link https://meshworld.in/convert-canvas-to-an-image-using-javascript/}
35
+ */
36
+ export declare function canvas2File(canvas: HTMLCanvasElement, fileName: string, lastModified: number, type?: string, quality?: number): Promise<File>;
37
+ export type ResizeResultType = 'image' | 'canvas';
38
+ /**
39
+ * 缩放图片
40
+ * @param img:HTMLImageElement 图片对象
41
+ * @param inputType 图片类型
42
+ * @param imageWidth 图片宽度
43
+ * @param imageHeight 图片高度
44
+ * @param equalProportion 是否等比例拉伸,默认是,目前只支持等比例拉伸
45
+ * @param sideLengthLimit 图片边长限制
46
+ * @param baseOnShortSide 是否以短边为限制
47
+ * @param resultType: ResizeResultType, "image" | "canvas"
48
+ */
49
+ export declare function resize(img: HTMLImageElement, { inputType, imageWidth, imageHeight, sideLengthLimit, baseOnShortSide, // 是否以短边为基准缩放
50
+ resultType, }: {
51
+ inputType?: string | undefined;
52
+ imageWidth?: number | undefined;
53
+ imageHeight?: number | undefined;
54
+ sideLengthLimit?: number | undefined;
55
+ baseOnShortSide?: boolean | undefined;
56
+ resultType?: string | undefined;
57
+ }): Promise<HTMLImageElement | HTMLCanvasElement>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * 水印配置 {@link http://faq.egova.com.cn:7777/projects/redmine/wiki/%E6%8B%8D%E7%85%A7%E6%B0%B4%E5%8D%B0%E9%85%8D%E7%BD%AE|文档}
3
+ * @description 水印渲染类
4
+ */
5
+ import 'dayjs/locale/zh-cn';
6
+ export interface WatermarkContextParams {
7
+ address: string;
8
+ watermarkTime: Date;
9
+ humanName: string;
10
+ projectName: string;
11
+ logo: string;
12
+ applicationName: string;
13
+ pixel: string;
14
+ width: string;
15
+ height: string;
16
+ }
17
+ export declare class WatermarkContext {
18
+ address: string;
19
+ watermarkTime: Date;
20
+ humanName: string;
21
+ projectName: string;
22
+ logo: string;
23
+ applicationName: string;
24
+ pixel: string;
25
+ width: string;
26
+ height: string;
27
+ /**
28
+ * 打水印需要的环境信息
29
+ * @param address
30
+ * @param watermarkTime
31
+ * @param humanName
32
+ * @param projectName
33
+ * @param logo
34
+ */
35
+ constructor(params: WatermarkContextParams);
36
+ }
37
+ export interface WatermarkOptionsParams {
38
+ enabled: boolean;
39
+ watermarkConfigString: string;
40
+ context: WatermarkContext;
41
+ }
42
+ export declare class WatermarkOptions {
43
+ enabled: boolean;
44
+ watermarkConfigString: string;
45
+ context: WatermarkContext;
46
+ /**
47
+ * 水印配置项
48
+ * @param enabled, 是否开启水印
49
+ * @param watermarkConfigString,水印配置的字符串
50
+ * @param context,打水印需要的环境信息
51
+ */
52
+ constructor(params: WatermarkOptionsParams);
53
+ }
54
+ /**
55
+ * A JavaScript Scanner like Java's
56
+ * @see java.util.Scanner
57
+ */
58
+ export declare class TextScanner {
59
+ private text;
60
+ private cursor;
61
+ /**
62
+ * The content to scan
63
+ * @param text
64
+ */
65
+ constructor(text: string);
66
+ hasNext(obj?: any): boolean;
67
+ next(obj?: any): string | RegExpMatchArray | null;
68
+ skip(obj?: string): TextScanner;
69
+ }
70
+ export declare function renderWatermark(canvas: HTMLCanvasElement, options: WatermarkOptions): Promise<HTMLCanvasElement>;
71
+ export declare function checkWatermarkConfigSupported(watermarkConfigString: string): boolean;