forked from external-repos/squoosh
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user