-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
119bcd8
commit 2a07d14
Showing
5 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
}, | ||
"license": "UNLICENSE", | ||
"devDependencies": { | ||
"@types/node": "^10.17.14", | ||
"canvas": "2.5.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/// <reference types="node" /> | ||
|
||
interface ByteArray { | ||
/** | ||
* Get the data as a Node.js `Buffer`. | ||
*/ | ||
getData(): Buffer | ||
} | ||
|
||
interface ImageDataLike { | ||
readonly data: Uint8ClampedArray | ||
} | ||
|
||
interface CanvasLike { | ||
getImageData(sx: number, sy: number, sw: number, sh: number): ImageDataLike | ||
} | ||
|
||
declare class GIFEncoder { | ||
/** | ||
* Create a new GIFEncoder | ||
* @param width the width of the images in pixels. | ||
* @param height the height of images in pixels. | ||
* @param algorithm `neuquant` or `octree`. `neuquant` if undefined. | ||
* @param useOptimizer enables/disables optimizer. `false` if undefined. | ||
* @param totalFrames total number of images. `0` if undefined. | ||
*/ | ||
constructor(width: number, | ||
height: number, | ||
algorithm?: "neuquant" | "octree", | ||
useOptimizer?: boolean, | ||
totalFrames?: number) | ||
|
||
/** | ||
* Starts the encoder. | ||
*/ | ||
start(): void | ||
|
||
/** | ||
* Adds a frame to the GIF. | ||
* @param context Node-canvas or DOM canvas context. | ||
*/ | ||
addFrame(context: CanvasLike): void | ||
|
||
/** | ||
* Sets delay between frames. Can be set once per frame. | ||
* @param delay Number of milliseconds to display frame | ||
*/ | ||
setDelay(delay: number): void | ||
|
||
/** | ||
* Sets gif framerate. Alternative to `setDelay`. | ||
* @param fps Number of frames per second to display. | ||
*/ | ||
setFrameRate(fps: number): void | ||
|
||
/** | ||
* Neuquant quality. | ||
* @param quality Neuquant quality. `1` to `30`. `1` is best/slowest. | ||
*/ | ||
setQuality(quality: number): void | ||
|
||
/** | ||
* Optimizer threshold percentage | ||
* @param threshold Optimizer threshold percentage, `0` to `100`. | ||
*/ | ||
setThreshold(threshold: number): void | ||
|
||
/** | ||
* Number of loops GIF does | ||
* @param repeat 0 is forever, anything else is literal number of loops | ||
*/ | ||
setRepeat(repeat: number): void | ||
|
||
/** | ||
* Stops the encoder. Call after all frames are added. | ||
*/ | ||
finish(): void | ||
|
||
/** | ||
* The raw bytes representing the resulting GIF. | ||
*/ | ||
out: ByteArray | ||
} | ||
export = GIFEncoder |
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,18 @@ | ||
import GIFEncoder = require("gif-encoder-2") | ||
import * as Canvas from "canvas" | ||
|
||
const canvas = Canvas.createCanvas(1, 1) | ||
const context = canvas.getContext("2d") | ||
const gif = new GIFEncoder(1, 1, "neuquant") | ||
gif.start() | ||
gif.setDelay(1) | ||
gif.setFrameRate(30) | ||
gif.setQuality(1) | ||
gif.setRepeat(0) | ||
gif.setThreshold(0) | ||
gif.addFrame(context) | ||
gif.finish() | ||
const image = gif.out.getData() | ||
|
||
const gif2 = new GIFEncoder(1, 1, "octree", true, 1) | ||
const gif3 = new GIFEncoder(1, 1) |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"noEmit": true, | ||
"baseUrl": ".", | ||
"paths": { "gif-encoder-2": ["."] } | ||
} | ||
} |