Skip to content

Instantly share code, notes, and snippets.

@heycqing
Created May 21, 2020 08:48
Show Gist options
  • Select an option

  • Save heycqing/28e8c81543b082db14cba7b59e604d34 to your computer and use it in GitHub Desktop.

Select an option

Save heycqing/28e8c81543b082db14cba7b59e604d34 to your computer and use it in GitHub Desktop.
判断是否支持检查webp格式
export const check_webp_support = () => {
return new Promise( reslove => {
let img = new Image();
img.onload = function () {
let result = (img.width > 0) && (img.height > 0);
reslove(result)
};
img.onerror = function () {
reslove(false)
};
img.src = "data:image/webp;base64," + "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==";
})
}
//原理: 生成一张src是webp格式的图片,通过判断图片大小是否存在
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment