feat(android): Capacitor APK build + native save/share bridge
- android/ — Capacitor project (build/, local.properties ignored) - app/js/native.js — bridge สำหรับ APK: savePhoto/saveZip/shareItems ผ่าน Filesystem+Share - app/js/csv.js — นำเข้าโฟลเดอร์หลายรายการจาก CSV (site,letter,datetime,name) - app/js/orient.js — จัดการ orientation ของ preview/กล้อง - app/manual.html + APK.md — คู่มือใช้งานและวิธี build APK - app/templates/folders-template.csv — เทมเพลต CSV - package.json / package-lock.json / capacitor.config.json / scripts/build-apk.sh - ปรับ ui, camera, exif, archive, db, naming, main, sw + css/README ตามงานข้างบน
This commit is contained in:
1 parent
a0bccc2316
commit
6f146aef59
75 files changed
+4637
-151
No files matched your search
+71
-3
@@ -125,6 +125,30 @@ export async function setZoom(value) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* บังคับให้เป็น JPEG จริง — EXIF ฝังได้เฉพาะ JPEG
|
||||
* (ImageCapture บางเครื่อง/บางเวอร์ชันคืน PNG กลับมา)
|
||||
*/
|
||||
async function toJpegBlob(blob, quality = JPEG_QUALITY) {
|
||||
if (!blob) return blob;
|
||||
const head = new Uint8Array(await blob.slice(0, 3).arrayBuffer());
|
||||
const isJpeg = head[0] === 0xff && head[1] === 0xd8;
|
||||
if (isJpeg) return blob.type === "image/jpeg" ? blob : new Blob([blob], { type: "image/jpeg" });
|
||||
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = bmp.width;
|
||||
canvas.height = bmp.height;
|
||||
canvas.getContext("2d").drawImage(bmp, 0, 0);
|
||||
bmp.close?.();
|
||||
const out = await new Promise((res) => canvas.toBlob(res, "image/jpeg", quality));
|
||||
return out || blob;
|
||||
} catch {
|
||||
return blob;
|
||||
}
|
||||
}
|
||||
|
||||
async function makeThumb(blob) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
@@ -142,18 +166,57 @@ async function makeThumb(blob) {
|
||||
}
|
||||
|
||||
/**
|
||||
* ถ่ายภาพนิ่ง
|
||||
/** ครอปกลางภาพให้ได้อัตราส่วนที่เลือก (4:3 = 1.333, 3:4 = 0.75) */
|
||||
async function cropToRatio(blob, ratio) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
const w = bmp.width, h = bmp.height;
|
||||
const src = w / h;
|
||||
let sw = w, sh = h, sx = 0, sy = 0;
|
||||
if (src > ratio + 0.002) {
|
||||
sw = Math.round(h * ratio);
|
||||
sx = Math.round((w - sw) / 2);
|
||||
} else if (src < ratio - 0.002) {
|
||||
sh = Math.round(w / ratio);
|
||||
sy = Math.round((h - sh) / 2);
|
||||
}
|
||||
if (sw === w && sh === h) { bmp.close?.(); return { blob, width: w, height: h }; }
|
||||
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = sw;
|
||||
canvas.height = sh;
|
||||
canvas.getContext("2d").drawImage(bmp, sx, sy, sw, sh, 0, 0, sw, sh);
|
||||
bmp.close?.();
|
||||
const out = await new Promise((res) => canvas.toBlob(res, "image/jpeg", JPEG_QUALITY));
|
||||
return { blob: out || blob, width: sw, height: sh };
|
||||
} catch {
|
||||
return { blob, width: 0, height: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
function ratioValue(label) {
|
||||
const m = /^(\d+)\s*[:x/]\s*(\d+)$/.exec(String(label || ""));
|
||||
if (!m) return 4 / 3;
|
||||
const a = Number(m[1]), b = Number(m[2]);
|
||||
return b ? a / b : 4 / 3;
|
||||
}
|
||||
|
||||
/** ถ่ายภาพนิ่ง
|
||||
* 1) ImageCapture.takePhoto() — ได้ JPEG ความละเอียดเต็มเซนเซอร์ + EXIF จากกล้อง (S23)
|
||||
* 2) fallback: วาดเฟรมวิดีโอลง canvas
|
||||
*/
|
||||
export async function captureStill() {
|
||||
export async function captureStill({ ratio = "4:3" } = {}) {
|
||||
if (!cam.track) throw camError("notready");
|
||||
let blob = null;
|
||||
let source = "canvas";
|
||||
|
||||
if (cam.imageCapture) {
|
||||
try {
|
||||
blob = await cam.imageCapture.takePhoto();
|
||||
// บางเครื่อง takePhoto() ค้างไม่ resolve → กันด้วย timeout แล้วตกไปใช้ canvas
|
||||
blob = await Promise.race([
|
||||
cam.imageCapture.takePhoto(),
|
||||
new Promise((_, rej) => setTimeout(() => rej(new Error("takePhoto timeout")), 4000)),
|
||||
]);
|
||||
source = "imagecapture";
|
||||
} catch { blob = null; }
|
||||
}
|
||||
@@ -171,6 +234,11 @@ export async function captureStill() {
|
||||
source = "canvas";
|
||||
}
|
||||
|
||||
// EXIF ฝังได้เฉพาะ JPEG → แปลงถ้าจำเป็น (ก่อนอ่านขนาด/ทำ thumb)
|
||||
blob = await toJpegBlob(blob);
|
||||
|
||||
// ครอป/จัดทิศทางทำที่ main.js (หลัง auto-orient) — ที่นี่คืนภาพดิบ
|
||||
|
||||
if (!width || !height) {
|
||||
try {
|
||||
const bmp = await createImageBitmap(blob);
|
||||
|
||||
Reference in new issue
Block a user