heic-to 1.2.2 → 1.3.0
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.
- package/README.md +11 -2
- package/dist/csp/heic-to.d.ts +28 -13
- package/dist/csp/heic-to.js +1 -1
- package/dist/csp/heic-to.min.js +1 -1
- package/dist/heic-to.d.ts +28 -13
- package/dist/heic-to.js +1 -1
- package/dist/heic-to.min.js +1 -1
- package/dist/iife/heic-to.js +19 -13
- package/dist/next/heic-to.d.ts +28 -13
- package/dist/next/heic-to.js +1 -1
- package/example/bitmap/app.js +28 -0
- package/example/bitmap/index.html +47 -0
- package/package.json +1 -1
- package/src/index.js +20 -14
- package/src/next/index.js +18 -23
package/dist/iife/heic-to.js
CHANGED
|
@@ -101,19 +101,25 @@ var HeicTo = (() => {
|
|
|
101
101
|
const ctx = canvas.getContext("2d");
|
|
102
102
|
ctx && ctx.clearRect(0, 0, 1, 1);
|
|
103
103
|
};
|
|
104
|
-
heicTo = (_0) => __async(null, [_0], function* ({ blob, type, quality }) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
heicTo = (_0) => __async(null, [_0], function* ({ blob, type, quality, options }) {
|
|
105
|
+
if (type == "bitmap") {
|
|
106
|
+
const imageBuffer = yield blob.arrayBuffer();
|
|
107
|
+
const imageData = yield decodeBuffer(imageBuffer);
|
|
108
|
+
return createImageBitmap(imageData, options);
|
|
109
|
+
} else {
|
|
110
|
+
const imageBuffer = yield blob.arrayBuffer();
|
|
111
|
+
let canvas;
|
|
112
|
+
try {
|
|
113
|
+
canvas = yield encodeByCanvas(imageBuffer);
|
|
114
|
+
return yield new Promise((resolve, reject) => canvas.toBlob((blob2) => {
|
|
115
|
+
if (blob2 != null)
|
|
116
|
+
resolve(blob2);
|
|
117
|
+
else
|
|
118
|
+
reject(`Can't convert canvas to blob.`);
|
|
119
|
+
}, type, quality));
|
|
120
|
+
} finally {
|
|
121
|
+
if (canvas) releaseCanvas(canvas);
|
|
122
|
+
}
|
|
117
123
|
}
|
|
118
124
|
});
|
|
119
125
|
}
|
package/dist/next/heic-to.d.ts
CHANGED
|
@@ -5,29 +5,44 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function isHeic(file: File): Promise<boolean>;
|
|
7
7
|
|
|
8
|
+
type ImageMime = `${"image"}/${string}`; // e.g. "image/jpeg", "image/png", "image/webp"
|
|
9
|
+
type HeicTarget = "bitmap" | ImageMime;
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* Converts a HEIC image to another format.
|
|
13
|
+
* @param args - The conversion options.
|
|
14
|
+
* @returns A promise that resolves to the converted image bitmap.
|
|
10
15
|
*/
|
|
11
|
-
export
|
|
16
|
+
export function heicTo(args: {
|
|
12
17
|
/**
|
|
13
18
|
* The HEIC image blob to convert.
|
|
14
19
|
*/
|
|
15
20
|
blob: Blob;
|
|
16
|
-
|
|
21
|
+
type: "bitmap";
|
|
17
22
|
/**
|
|
18
|
-
*
|
|
23
|
+
* Options for creating the ImageBitmap.
|
|
19
24
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* The quality of the output image, between 0 and 1.
|
|
24
|
-
*/
|
|
25
|
-
quality?: number;
|
|
26
|
-
}
|
|
25
|
+
options?: ImageBitmapOptions;
|
|
26
|
+
quality?: never;
|
|
27
|
+
}): Promise<ImageBitmap>;
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Converts a HEIC image to another format.
|
|
30
|
-
* @param
|
|
31
|
+
* @param args - The conversion options.
|
|
31
32
|
* @returns A promise that resolves to the converted image blob.
|
|
32
33
|
*/
|
|
33
|
-
export
|
|
34
|
+
export function heicTo<M extends Exclude<HeicTarget, "bitmap">>(args: {
|
|
35
|
+
/**
|
|
36
|
+
* The HEIC image blob to convert.
|
|
37
|
+
*/
|
|
38
|
+
blob: Blob;
|
|
39
|
+
/**
|
|
40
|
+
* The desired output image MIME type (e.g., 'image/jpeg', 'image/png').
|
|
41
|
+
*/
|
|
42
|
+
type: M;
|
|
43
|
+
/**
|
|
44
|
+
* The quality of the output image, between 0 and 1.
|
|
45
|
+
*/
|
|
46
|
+
quality?: number; // 0..1 for JPEG/WEBP, ignored by PNG
|
|
47
|
+
options?: never;
|
|
48
|
+
}): Promise<Blob>;
|