-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web reader): conditional webp support
closes #65
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// check_webp_feature: | ||
// 'feature' can be one of 'lossy', 'lossless', 'alpha' or 'animation'. | ||
// 'callback(feature, isSupported)' will be passed back the detection result (in an asynchronous way!) | ||
export function checkWebpFeature (feature: string, callback: (feature: string, isSupported: boolean) => void) { | ||
const kTestImages: any = { | ||
lossy: 'UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA', | ||
lossless: 'UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==', | ||
alpha: 'UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==', | ||
animation: 'UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA' | ||
} | ||
const img = new Image() | ||
img.onload = function () { | ||
const result = (img.width > 0) && (img.height > 0) | ||
callback(feature, result) | ||
} | ||
img.onerror = function () { | ||
callback(feature, false) | ||
} | ||
img.src = 'data:image/webp;base64,' + kTestImages[feature] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters