From a6e6c575c8e755486cc148a31c9afeea4ad286c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9B=90=EB=8D=94?= Date: Mon, 11 Jan 2021 22:06:29 +0900 Subject: [PATCH] feat: added method for check webp is available --- utils/Tools.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/Tools.ts b/utils/Tools.ts index 589e843..655ee0c 100644 --- a/utils/Tools.ts +++ b/utils/Tools.ts @@ -20,4 +20,14 @@ export function checkPerm(base: number, required: number | UserPemissionFlags):b export function makeImageURL(root:string, { format='png', size=256 }:ImageOptions):string { return `${root}.${format}?size=${size}` +} + +export function supportsWebP() { + const elem = document.createElement('canvas') + if (elem.getContext && elem.getContext('2d')) { + // was able or not to get WebP representation + return elem.toDataURL('image/webp').indexOf('data:image/webp') == 0 + } + // very old browser like IE 8, canvas not supported + return false } \ No newline at end of file