This commit is contained in:
Manav Rathi 2024-05-16 10:52:00 +05:30
parent 7d122f825c
commit 6ce956c5bb
No known key found for this signature in database
2 changed files with 6 additions and 7 deletions

View file

@ -220,8 +220,7 @@ class FaceService {
face.detection, face.detection,
); );
const blobOptions = DEFAULT_ML_SYNC_CONFIG.faceCrop.blobOptions; const blob = await imageBitmapToBlob(faceCrop.image);
const blob = await imageBitmapToBlob(faceCrop.image, blobOptions);
const cache = await openCache("face-crops"); const cache = await openCache("face-crops");
await cache.put(face.id, blob); await cache.put(face.id, blob);

View file

@ -450,17 +450,17 @@ export interface BlobOptions {
quality?: number; quality?: number;
} }
export async function imageBitmapToBlob( export async function imageBitmapToBlob(imageBitmap: ImageBitmap) {
imageBitmap: ImageBitmap,
options?: BlobOptions,
) {
const offscreen = new OffscreenCanvas( const offscreen = new OffscreenCanvas(
imageBitmap.width, imageBitmap.width,
imageBitmap.height, imageBitmap.height,
); );
offscreen.getContext("2d").drawImage(imageBitmap, 0, 0); offscreen.getContext("2d").drawImage(imageBitmap, 0, 0);
return offscreen.convertToBlob(options); return offscreen.convertToBlob({
type: "image/jpeg",
quality: 0.8,
});
} }
export async function imageBitmapFromBlob(blob: Blob) { export async function imageBitmapFromBlob(blob: Blob) {