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
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {heicTo, isHeic} from '../../dist/heic-to.js'
|
|
2
|
+
|
|
3
|
+
const imagesContainer = document.querySelector(".images")
|
|
4
|
+
const messageLabel = document.querySelector("label")
|
|
5
|
+
const field = document.querySelector("input")
|
|
6
|
+
|
|
7
|
+
field.addEventListener('change', async (event) => {
|
|
8
|
+
|
|
9
|
+
let canvasDom = document.querySelector("canvas")
|
|
10
|
+
if (!canvasDom) {
|
|
11
|
+
canvasDom = document.createElement('canvas')
|
|
12
|
+
imagesContainer.appendChild(canvasDom)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const image = field.files[0]
|
|
16
|
+
if (await isHeic(image)) {
|
|
17
|
+
messageLabel.textContent = "It's a HEIC image"
|
|
18
|
+
const bitmapImage = await heicTo({blob: image, type: 'bitmap', options: {imageOrientation: 'flipY'}})
|
|
19
|
+
const ctx = canvasDom.getContext('2d')
|
|
20
|
+
canvasDom.width = bitmapImage.width
|
|
21
|
+
canvasDom.height = bitmapImage.height
|
|
22
|
+
ctx.drawImage(bitmapImage, 0, 0)
|
|
23
|
+
} else {
|
|
24
|
+
messageLabel.textContent = "It's not a HEIC image"
|
|
25
|
+
canvasDom.remove()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>heic-to</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
display: flex;
|
|
10
|
+
justify-content: center;
|
|
11
|
+
align-items: center;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
height: 100vh;
|
|
14
|
+
}
|
|
15
|
+
input {
|
|
16
|
+
border: 1px solid black;
|
|
17
|
+
padding: 10px;
|
|
18
|
+
}
|
|
19
|
+
label {
|
|
20
|
+
display: block;;
|
|
21
|
+
padding-top: 20px;
|
|
22
|
+
padding-bottom: 20px;
|
|
23
|
+
color: red;
|
|
24
|
+
}
|
|
25
|
+
.images {
|
|
26
|
+
width: 200px;
|
|
27
|
+
height: 200px;
|
|
28
|
+
}
|
|
29
|
+
img {
|
|
30
|
+
display: block;
|
|
31
|
+
width: 100%;
|
|
32
|
+
}
|
|
33
|
+
</style>
|
|
34
|
+
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, post-check=0, pre-check=0">
|
|
35
|
+
<script src="./app.js" type="module"></script>
|
|
36
|
+
</head>
|
|
37
|
+
<body>
|
|
38
|
+
|
|
39
|
+
<h1>heic-to</h1>
|
|
40
|
+
|
|
41
|
+
<main>
|
|
42
|
+
<input type="file">
|
|
43
|
+
<label></label>
|
|
44
|
+
<div class="images"></div>
|
|
45
|
+
</main>
|
|
46
|
+
</body>
|
|
47
|
+
</html>
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -79,23 +79,29 @@ const releaseCanvas = (canvas) => {
|
|
|
79
79
|
ctx && ctx.clearRect(0, 0, 1, 1);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const heicTo = async ({blob, type, quality}) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
const heicTo = async ({blob, type, quality, options}) => {
|
|
83
|
+
if (type == "bitmap") {
|
|
84
|
+
const imageBuffer = await blob.arrayBuffer();
|
|
85
|
+
const imageData = await decodeBuffer(imageBuffer);
|
|
86
|
+
return createImageBitmap(imageData, options);
|
|
87
|
+
} else {
|
|
88
|
+
const imageBuffer = await blob.arrayBuffer()
|
|
89
|
+
let canvas;
|
|
90
|
+
try {
|
|
91
|
+
canvas = await encodeByCanvas(imageBuffer);
|
|
92
|
+
return await new Promise((resolve, reject) => canvas.toBlob(blob => {
|
|
93
|
+
if (blob != null)
|
|
94
|
+
resolve(blob);
|
|
95
|
+
else
|
|
96
|
+
reject(`Can't convert canvas to blob.`);
|
|
97
|
+
}, type, quality));
|
|
98
|
+
} finally {
|
|
99
|
+
if (canvas) releaseCanvas(canvas);
|
|
100
|
+
}
|
|
95
101
|
}
|
|
96
102
|
};
|
|
97
103
|
|
|
98
104
|
export {
|
|
99
105
|
isHeic,
|
|
100
|
-
heicTo
|
|
106
|
+
heicTo,
|
|
101
107
|
}
|
package/src/next/index.js
CHANGED
|
@@ -77,34 +77,29 @@ const releaseCanvas = (canvas) => {
|
|
|
77
77
|
ctx && ctx.clearRect(0, 0, 1, 1);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const heicTo = async ({blob, type, quality}) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (blob) {
|
|
80
|
+
const heicTo = async ({blob, type, quality, options}) => {
|
|
81
|
+
if (type == "bitmap") {
|
|
82
|
+
const imageBuffer = await blob.arrayBuffer();
|
|
83
|
+
const imageData = await decodeBuffer(imageBuffer);
|
|
84
|
+
return createImageBitmap(imageData, options);
|
|
85
|
+
} else {
|
|
86
|
+
const imageBuffer = await blob.arrayBuffer()
|
|
87
|
+
let canvas;
|
|
88
|
+
try {
|
|
89
|
+
canvas = await encodeByCanvas(imageBuffer);
|
|
90
|
+
return await new Promise((resolve, reject) => canvas.toBlob(blob => {
|
|
91
|
+
if (blob != null)
|
|
93
92
|
resolve(blob);
|
|
94
|
-
|
|
93
|
+
else
|
|
95
94
|
reject(`Can't convert canvas to blob.`);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
} finally {
|
|
103
|
-
if (canvas) releaseCanvas(canvas);
|
|
95
|
+
}, type, quality));
|
|
96
|
+
} finally {
|
|
97
|
+
if (canvas) releaseCanvas(canvas);
|
|
98
|
+
}
|
|
104
99
|
}
|
|
105
100
|
};
|
|
106
101
|
|
|
107
102
|
export {
|
|
108
103
|
isHeic,
|
|
109
|
-
heicTo
|
|
104
|
+
heicTo,
|
|
110
105
|
}
|