From 2e83971c18c4b15137da90aba375741be2dfa3c0 Mon Sep 17 00:00:00 2001 From: leejh Date: Fri, 8 Nov 2019 08:41:41 +0900 Subject: [PATCH] > video file upload thumbnail image resize. > extention tolowercase > video type message-box layout modify --- .../src/lib/services/common-api.service.ts | 2 +- .../src/lib/utils/file.util.ts | 28 +++++++++++++++++-- .../message-box/video.component.html | 4 ++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts index 099d8f9c..4ec66383 100644 --- a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts +++ b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts @@ -185,7 +185,7 @@ export class CommonApiService { public acceptableExtensionForFileTalk(extensions: string[]): boolean { for (const extension of extensions) { if ( - -1 === this.moduleConfig.acceptableFileExtensions.indexOf(extension) + -1 === this.moduleConfig.acceptableFileExtensions.indexOf(extension.toLowerCase()) ) { return false; } diff --git a/projects/ucap-webmessenger-core/src/lib/utils/file.util.ts b/projects/ucap-webmessenger-core/src/lib/utils/file.util.ts index 98f5cc07..387f3cef 100644 --- a/projects/ucap-webmessenger-core/src/lib/utils/file.util.ts +++ b/projects/ucap-webmessenger-core/src/lib/utils/file.util.ts @@ -80,8 +80,32 @@ export class FileUtil { const snapImage = () => new Promise((imgResolve, imgReject) => { const canvas = document.createElement('canvas'); - canvas.width = video.videoWidth; - canvas.height = video.videoHeight; + + // thumbnail image resize + const width = video.videoWidth; + const height = video.videoHeight; + let resizeWidth = 0; + let resizeHeight = 0; + + // max size + const maxWidth = 320; + const maxHeight = 320; + + if (width > maxWidth || height > maxHeight) { + if (width > height) { + resizeWidth = maxWidth; + resizeHeight = Math.round((height * resizeWidth) / width); + } else { + resizeHeight = maxHeight; + resizeWidth = Math.round((width * resizeHeight) / height); + } + } else { + resizeWidth = width; + resizeHeight = height; + } + + canvas.width = resizeWidth; + canvas.height = resizeHeight; canvas .getContext('2d') .drawImage(video, 0, 0, canvas.width, canvas.height); diff --git a/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/video.component.html b/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/video.component.html index ecc19459..4c61ae6e 100644 --- a/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/video.component.html +++ b/projects/ucap-webmessenger-ui-chat/src/lib/components/message-box/video.component.html @@ -1,7 +1,9 @@
- +
+ +