guetzli-js
Guetzli is a JPEG encoder that aims for excellent compression density at high visual quality. Guetzli-generated images are typically 20-30% smaller than images of equivalent quality generated by libjpeg.
Guetzli for NodeJS/Browser
Demo
This demo show guetzli-js in browser, encode a canvas and save as a jpeg file.
Browser suggest: Chrome, Firefox, Edge. Chrome is the best choice!
Install
Windows
$ npm install -g windows-build-tool
$ npm install -g node-gyp
$ node-gyp install
$ npm install -g guetzli-js
macOS and Linux
$ npm install -g node-gyp
$ node-gyp install
$ npm install -g guetzli-js
guetzli-cli
Command: $ guetzli-cli bees.png bees.jpg
Done
$ guetzli-cli -h
Usage: guetzli input_filename output_filename
$ guetzli-cli -v
guetzli-1.0.1
Guetzli API
Image Type:
// const image = require('guetzli-js/dist/lib/image')
Guetzli API:
// const guetzli = require('guetzli-js')// const guetzli_asmjs = require('guetzli-js/dist/lib/cxx-emscripten/guetzli.out') ; // google/guetzli version; // 84; // 110; // 95 ; ; ; ;
Helpers (NodeJS Only):
// const helper = require('guetzli-js/dist/lib/helper') ;; ; ; // only for jpg/png format;
Examples
NodeJS
const fs = const guetzli = const helper = // load pnglet data = fs // decode png imagelet m = helper // encode jpg imagelet jpegData = guetzli // save jpgfs
Borwser
Hello show imageSave As...
Borwser: Settings
RGB <==> Gray
{ ifstride == 0 stride = width let rgb = width*height*3 forlet y = 0; y < height; y++ forlet x = 0; x < width; x++ let V = grayy*stride + x rgby*width+x*3+0 = V // R rgby*width+x*3+1 = V // G rgby*width+x*3+2 = V // B return rgb} { ifstride == 0 stride = width*3 let gray = width*height forlet y = 0; y < height; y++ forlet x = 0; x < width; x++ let idx = y*stride + x let R = rgbidx*3+0 let G = rgbidx*3+1 let B = rgbidx*3+2 grayoff++ = R+G+B/3|0 return gray}
Other
Benchmark
$ gulp bench
[09:12:33] Running suite Guetzli [D:\work\guetzli-js\dist\lib\bench.js]...
[09:12:52] encodeImage.bees-small.rgb x 0.63 ops/sec ±0.81% (6 runs sampled)
[09:13:22] encodeImage.asm.bees-small.rgb x 0.35 ops/sec ±2.18% (5 runs sampled)
[09:13:27] helper.encodeJpg.bees-small.rgb x 1,464 ops/sec ±0.79% (94 runs sampled)
[09:13:33] helper.encodePng.bees-small.rgb x 173 ops/sec ±1.32% (82 runs sampled)
[09:13:33] Fastest test is helper.encodeJpg.bees-small.rgb at 8.5x faster than helper.encodePng.bees-small.rgb
Unit Test
$ npm test
> guetzli-js@1.0.8 test D:\work\guetzli-js
> nodeunit dist/lib/test.js
test.js
√ testVersion
√ testIsPngFilename
√ testIsJpegFilename
√ testLoadImage_png
√ testLoadImage_jpeg
√ testGuetzliEncode
OK: 21 assertions (12483ms)
guetzli.node
with CMake
Build Windows x64
- Install CMake 3.5+
- Install VS2015
- run
build-win64.bat
in command line
Windows x86
- Install CMake 3.5+
- Install VS2015
- run
build-win32.bat
in command line
Darwin or Linux
- Install CMake 3.5+
- Install GCC
mkdir build
cd build && cmake .. && make install
lib/cxx-emscripten/guetzli.out.js
with Emscripten
Build - Install Emscripten
make
NPM mirror for China
- https://npm.taobao.org/
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g windows-build-tool
(Windows)cnpm install -g node-gyp
cnpm install -g guetzli-js
License
MIT © chai2010