summaryrefslogtreecommitdiffstats
path: root/ui/src/utils.ts
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-06-04 21:40:57 -0400
committerDessalines <tyhou13@gmx.com>2020-06-04 21:40:57 -0400
commitee32072489bd818294a8b300f8ca2beaf23640bc (patch)
tree9906359b1fc8f076edc530a1b735f87b697ef6df /ui/src/utils.ts
parent2e882f75f2d8cd517f965d9c93af5443e957a811 (diff)
Fixing webp issue for safari.
Diffstat (limited to 'ui/src/utils.ts')
-rw-r--r--ui/src/utils.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/ui/src/utils.ts b/ui/src/utils.ts
index 190fcf57..cb56ba58 100644
--- a/ui/src/utils.ts
+++ b/ui/src/utils.ts
@@ -423,7 +423,7 @@ export function objectFlip(obj: any) {
export function pictshareAvatarThumbnail(src: string): string {
// sample url: http://localhost:8535/pictshare/gs7xuu.jpg
let split = src.split('pictshare');
- let out = `${split[0]}pictshare/webp/96${split[1]}`;
+ let out = `${split[0]}pictshare/${canUseWebP() ? 'webp/' : ''}96${split[1]}`;
return out;
}
@@ -448,7 +448,9 @@ export function pictshareImage(
hash = split[1];
}
- let out = `${root}/webp/${thumbnail ? '192/' : ''}${hash}`;
+ let out = `${root}/${canUseWebP() ? 'webp/' : ''}${
+ thumbnail ? '192/' : ''
+ }${hash}`;
return out;
}
@@ -859,3 +861,18 @@ export function previewLines(text: string, lines: number = 3): string {
.slice(0, lines * 2)
.join('\n');
}
+
+function canUseWebP() {
+ var elem = document.createElement('canvas');
+
+ if (!!(elem.getContext && elem.getContext('2d'))) {
+ var testString = !(window.mozInnerScreenX == null) ? 'png' : 'webp';
+ // was able or not to get WebP representation
+ return (
+ elem.toDataURL('image/webp').startsWith('data:image/' + testString)
+ );
+ }
+
+ // very old browser like IE 8, canvas not supported
+ return false;
+}