Skip to content

Commit

Permalink
Support gifs
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilwanner committed Jun 14, 2020
1 parent c41bad0 commit a118a45
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/optimize/gif.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LoaderOptions } from '../options';

/**
* Optimize a gif image using gifsicle
*
* @async
* @param {Buffer} image Input image
* @param {LoaderOptions['gifsicle']} [options] Gifsicle options
* @returns {Buffer} Optimized image
*/
const optimizeGif = async (image: Buffer, options?: LoaderOptions['gifsicle']): Promise<Buffer> => { // eslint-disable-line
// optimize the image using gifsicle
return image;
};

export default optimizeGif;
5 changes: 5 additions & 0 deletions src/optimize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LoaderOptions } from '../options';
import optimizePng from './png';
import optimizeWebp from './webp';
import optimizeSvg from './svg';
import optimizeGif from './gif';

const sharpBasedOptimizers = {
jpeg: {
Expand All @@ -25,6 +26,10 @@ const rawBufferBasedOptimizers = {
handler: optimizeSvg,
optionsKey: 'svgo',
},
gif: {
handler: optimizeGif,
optionsKey: 'gifsicle',
},
} as Record<string, { handler: (image: Buffer, options?: unknown) => Promise<Buffer>; optionsKey: string }>;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/optimize/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LoaderOptions } from '../options';
* Optimize a svg image using svgo
*
* @async
* @param {Sharp} image Sharp wrapped input image
* @param {Buffer} image Input image
* @param {LoaderOptions['svgo']} [options] Svgo options
* @returns {Buffer} Optimized image
*/
Expand Down
1 change: 1 addition & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface LoaderOptions {
mozjpeg?: MozjpegOptions;
oxipng?: OxipngOptions;
webp?: WebpOptions;
gifsicle?: unknown;
svgo?: Record<string, unknown>;
}

Expand Down

0 comments on commit a118a45

Please sign in to comment.