diff --git a/app/package-lock.json b/app/package-lock.json index 9de9045..b4317cf 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -4990,6 +4990,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/browser-image-compression/-/browser-image-compression-2.0.2.tgz", "integrity": "sha512-pBLlQyUf6yB8SmmngrcOw3EoS4RpQ1BcylI3T9Yqn7+4nrQTXJD4sJDe5ODnJdrvNMaio5OicFo75rDyJD2Ucw==", + "license": "MIT", "dependencies": { "uzip": "0.20201231.0" } diff --git a/app/src/app/camera/page.tsx b/app/src/app/camera/page.tsx index 457cfbd..c43cf8f 100644 --- a/app/src/app/camera/page.tsx +++ b/app/src/app/camera/page.tsx @@ -17,6 +17,7 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Toaster } from "@/components/ui/sonner"; import type { ScoreResponse, User, todayAssignment } from "@/types"; +import imageCompression from "browser-image-compression"; import type React from "react"; import { useEffect, useRef, useState } from "react"; import { Camera, type CameraType } from "react-camera-pro"; @@ -163,10 +164,24 @@ const CameraApp = () => { setIsUploading(true); try { const base64Response = await fetch(imageData); - const blob = await base64Response.blob(); + const originalBlob = await base64Response.blob(); + + const compressOptions = { + maxSizeMB: 0.01, + maxWidthOrHeight: 1920, + useWebWorker: true, + }; + + const originalFile = new File([originalBlob], "tempImage", { + type: originalBlob.type, + }); + + const compressedBlob = await imageCompression( + originalFile, + compressOptions, + ); // 拡張子取得 - const compressedBlob = blob; // Assuming no compression is needed const Extension = compressedBlob.type.split("/")[1]; // 日付取得