Support webp images for community share button

#214
Files changed (1) hide show
  1. share_btn.py +7 -0
share_btn.py CHANGED
@@ -31,9 +31,16 @@ share_js = """async () => {
31
  console.log(blob.type)
32
  const imgId = Date.now() % 200;
33
  const isPng = blob.type == 'image/png';
 
 
 
 
34
  if(isPng){
35
  const fileName = `sd-perception-${imgId}.png`;
36
  return new File([blob], fileName, { type: 'image/png' });
 
 
 
37
  }else{
38
  const fileName = `sd-perception-${imgId}.jpg`;
39
  return new File([blob], fileName, { type: 'image/jpeg' });
 
31
  console.log(blob.type)
32
  const imgId = Date.now() % 200;
33
  const isPng = blob.type == 'image/png';
34
+ const isWebp = blob.type == 'image/webp';
35
+ const isOctetStream = blob.type == 'application/octet-stream';
36
+ const isLikelyWebp = isOctetStream && imgEl.src.toLowerCase().endsWith('.webp');
37
+
38
  if(isPng){
39
  const fileName = `sd-perception-${imgId}.png`;
40
  return new File([blob], fileName, { type: 'image/png' });
41
+ }else if(isWebp || isLikelyWebp){
42
+ const fileName = `sd-perception-${imgId}.webp`;
43
+ return new File([blob], fileName, { type: 'image/webp' });
44
  }else{
45
  const fileName = `sd-perception-${imgId}.jpg`;
46
  return new File([blob], fileName, { type: 'image/jpeg' });