All the encoders that Chrome/Safari/Firefox support out of the box. (#74)

* All the encoders that Chrome/Safari/Firefox support out of the box.

* Typo
This commit is contained in:
Jake Archibald
2018-07-02 19:10:10 +01:00
committed by GitHub
parent 807a76d443
commit 3867448aad
10 changed files with 134 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import { canvasEncode } from '../../lib/util';
import { canvasEncodeTest } from '../generic/util';
export interface EncodeOptions { quality: number; }
export interface EncoderState { type: typeof type; options: EncodeOptions; }
@@ -8,15 +9,7 @@ export const label = 'Browser WebP';
export const mimeType = 'image/webp';
export const extension = 'webp';
export const defaultOptions: EncodeOptions = { quality: 0.5 };
export async function featureTest() {
const data = new ImageData(1, 1);
const blob = await encode(data, defaultOptions);
// According to the spec, the blob should be null if the format isn't supported…
if (!blob) return false;
// …but Safari falls back to PNG, so we need to check the mime type.
return blob.type === mimeType;
}
export const featureTest = () => canvasEncodeTest(mimeType);
export function encode(data: ImageData, { quality }: EncodeOptions) {
return canvasEncode(data, mimeType, quality);