-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding WebP (without feature detect in place) * Adding WebP check * Remove unused import
- Loading branch information
1 parent
a09ec26
commit 6872997
Showing
5 changed files
with
94 additions
and
20 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,23 @@ | ||
import { canvasEncode } from '../../lib/util'; | ||
|
||
export interface EncodeOptions { quality: number; } | ||
export interface EncoderState { type: typeof type; options: EncodeOptions; } | ||
|
||
export const type = 'browser-webp'; | ||
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 function encode(data: ImageData, { quality }: EncodeOptions) { | ||
return canvasEncode(data, mimeType, quality); | ||
} |
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,3 @@ | ||
import qualityOption from '../generic/quality-option'; | ||
|
||
export default qualityOption({ min: 0, max: 1, step: 0 }); |
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
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
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