summaryrefslogtreecommitdiff
path: root/packages/frontend/src/utility/isWebpSupported.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/utility/isWebpSupported.ts')
-rw-r--r--packages/frontend/src/utility/isWebpSupported.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/frontend/src/utility/isWebpSupported.ts b/packages/frontend/src/utility/isWebpSupported.ts
new file mode 100644
index 0000000000..affd81fd57
--- /dev/null
+++ b/packages/frontend/src/utility/isWebpSupported.ts
@@ -0,0 +1,15 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+let isWebpSupportedCache: boolean | undefined;
+export function isWebpSupported() {
+ if (isWebpSupportedCache === undefined) {
+ const canvas = window.document.createElement('canvas');
+ canvas.width = 1;
+ canvas.height = 1;
+ isWebpSupportedCache = canvas.toDataURL('image/webp').startsWith('data:image/webp');
+ }
+ return isWebpSupportedCache;
+}