mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Optipng (#156)
* omg it’s compiling * example actually works * Expose compression level options * Disable crypto and path module emulation in webpack * Update README * Remove small image * Use -O3 on optipng * Free memory after copy * Handle unexpected file reader return types * Rename level label to effort
This commit is contained in:
23
src/codecs/optipng/encoder.ts
Normal file
23
src/codecs/optipng/encoder.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { canvasEncode, blobToArrayBuffer } from '../../lib/util';
|
||||
import EncodeWorker from './Encoder.worker';
|
||||
|
||||
export interface EncodeOptions {
|
||||
level: number;
|
||||
}
|
||||
export interface EncoderState { type: typeof type; options: EncodeOptions; }
|
||||
|
||||
export const type = 'png';
|
||||
export const label = 'OptiPNG';
|
||||
export const mimeType = 'image/png';
|
||||
export const extension = 'png';
|
||||
|
||||
export const defaultOptions: EncodeOptions = {
|
||||
level: 2,
|
||||
};
|
||||
|
||||
export async function encode(data: ImageData, opts: EncodeOptions): Promise<ArrayBuffer> {
|
||||
const pngBlob = await canvasEncode(data, mimeType);
|
||||
const pngBuffer = await blobToArrayBuffer(pngBlob);
|
||||
const encodeWorker = await new EncodeWorker();
|
||||
return encodeWorker.compress(pngBuffer, opts);
|
||||
}
|
||||
Reference in New Issue
Block a user