mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-16 10:39:53 +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:
@@ -9,6 +9,7 @@ import { FileDropEvent } from './custom-els/FileDrop';
|
||||
import './custom-els/FileDrop';
|
||||
|
||||
import * as quantizer from '../../codecs/imagequant/quantizer';
|
||||
import * as optiPNG from '../../codecs/optipng/encoder';
|
||||
import * as mozJPEG from '../../codecs/mozjpeg/encoder';
|
||||
import * as webP from '../../codecs/webp/encoder';
|
||||
import * as identity from '../../codecs/identity/encoder';
|
||||
@@ -89,6 +90,7 @@ async function compressImage(
|
||||
): Promise<File> {
|
||||
const compressedData = await (() => {
|
||||
switch (encodeData.type) {
|
||||
case optiPNG.type: return optiPNG.encode(image, encodeData.options);
|
||||
case mozJPEG.type: return mozJPEG.encode(image, encodeData.options);
|
||||
case webP.type: return webP.encode(image, encodeData.options);
|
||||
case browserPNG.type: return browserPNG.encode(image, encodeData.options);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { h, Component } from 'preact';
|
||||
import * as style from './style.scss';
|
||||
import { bind } from '../../lib/util';
|
||||
import { cleanSet, cleanMerge } from '../../lib/clean-modify';
|
||||
import OptiPNGEncoderOptions from '../../codecs/optipng/options';
|
||||
import MozJpegEncoderOptions from '../../codecs/mozjpeg/options';
|
||||
import BrowserJPEGEncoderOptions from '../../codecs/browser-jpeg/options';
|
||||
import WebPEncoderOptions from '../../codecs/webp/options';
|
||||
@@ -11,6 +12,7 @@ import BrowserWebPEncoderOptions from '../../codecs/browser-webp/options';
|
||||
import QuantizerOptionsComponent from '../../codecs/imagequant/options';
|
||||
|
||||
import * as identity from '../../codecs/identity/encoder';
|
||||
import * as optiPNG from '../../codecs/optipng/encoder';
|
||||
import * as mozJPEG from '../../codecs/mozjpeg/encoder';
|
||||
import * as webP from '../../codecs/webp/encoder';
|
||||
import * as browserPNG from '../../codecs/browser-png/encoder';
|
||||
@@ -35,6 +37,7 @@ import { PreprocessorState } from '../../codecs/preprocessors';
|
||||
|
||||
const encoderOptionsComponentMap = {
|
||||
[identity.type]: undefined,
|
||||
[optiPNG.type]: OptiPNGEncoderOptions,
|
||||
[mozJPEG.type]: MozJpegEncoderOptions,
|
||||
[webP.type]: WebPEncoderOptions,
|
||||
[browserPNG.type]: undefined,
|
||||
@@ -143,7 +146,7 @@ export default class Options extends Component<Props, State> {
|
||||
options={
|
||||
// Casting options, as encoderOptionsComponentMap[encodeData.type] ensures the correct
|
||||
// type, but typescript isn't smart enough.
|
||||
encoderState.options as typeof EncoderOptionComponent['prototype']['props']['options']
|
||||
encoderState.options as any
|
||||
}
|
||||
onChange={onEncoderOptionsChange}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user