From f8527375a09cf0284987aaa42d4767fc672ba02f Mon Sep 17 00:00:00 2001 From: Abhinav-grd Date: Tue, 16 Feb 2021 15:36:49 +0530 Subject: [PATCH] updated thumbnail dimension calulation logic --- src/services/uploadService.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/services/uploadService.ts b/src/services/uploadService.ts index 4cf1f4bec..61dd86f51 100644 --- a/src/services/uploadService.ts +++ b/src/services/uploadService.ts @@ -10,8 +10,7 @@ const CryptoWorker: any = Comlink.wrap(new Worker('worker/crypto.worker.js', { type: 'module' })); const ENDPOINT = getEndpoint(); -const THUMBNAIL_WIDTH = 1920; -const THUMBNAIL_HEIGHT = 1080; +const THUMBNAIL_HEIGHT = 720; const MAX_ATTEMPTS = 3; const MIN_THUMBNAIL_SIZE = 50000; @@ -388,13 +387,15 @@ class UploadService { image.setAttribute('src', imageURL); await new Promise((resolve) => { image.onload = () => { - canvas.width = THUMBNAIL_WIDTH; + const thumbnailWidth = + (image.width * THUMBNAIL_HEIGHT) / image.height; + canvas.width = thumbnailWidth; canvas.height = THUMBNAIL_HEIGHT; canvas_CTX.drawImage( image, 0, 0, - THUMBNAIL_WIDTH, + thumbnailWidth, THUMBNAIL_HEIGHT ); image = undefined; @@ -406,13 +407,16 @@ class UploadService { let video = document.createElement('video'); imageURL = URL.createObjectURL(file); video.addEventListener('loadeddata', function () { - canvas.width = THUMBNAIL_WIDTH; + const thumbnailWidth = + (video.videoWidth * THUMBNAIL_HEIGHT) / + video.videoHeight; + canvas.width = thumbnailWidth; canvas.height = THUMBNAIL_HEIGHT; canvas_CTX.drawImage( video, 0, 0, - THUMBNAIL_WIDTH, + thumbnailWidth, THUMBNAIL_HEIGHT ); resolve(null);