Emscripten mozjpeg port
Repository npm CoffeeScript Download
npm install emozjpeg@0.0.3
Port of MozJPEG project to Emscripten.
Example using Browserify tool:
```coffeescript
{encode} = require "emozjpeg"
image = new Image
image.onload = -> # get image size {width, height} = image
# create canvas and set size canvas = document.createElement "canvas" canvas.width = width canvas.height = height
# get drawing context context = canvas.getContext "2d" # draw image to canvas context.drawImage image, 0, 0, width, height
# get raw image data {data} = context.getImageData 0, 0, width, height
# encode image result = encode {data, width, height, quality, sampling, flags}
# load data to blob blob = new Blob [result], type: 'text/html' # create object url url = URL.createObjectURL blob
# load encoded image image.src = url
image.src = "path/to/originalImage.jpg" ```
npm install emozjpeg
```coffeescript
{encode} = require "emozjpeg"
{readFileSync, writeFileSync} = require "fs"
Canvas = require "canvas" {Image} = Canvas
image = new Image
image.src = readFileSync "originalImage.jpg"
{width, height} = image
canvas = new Canvas 100, 100 canvas.width = width canvas.height = height
context = canvas.getContext "2d"
context.drawImage image, 0, 0, width, height
{data} = context.getImageData 0, 0, width, height
result = encode {data, width, height, quality, sampling, flags}
writeFileSync "convertedImage.jpg", result ```
``` usage: convert [options]
-f, --flags=BOTTOMUP,FASTUPSAMPLE,FASTDCT,ACCURATEDCT coma-separated conversion flags (default: none) -h, --help display help & usage -o, --output=IMAGE output image -q, --quality=PERCENT jpeg quality (default: 70) -s, --sampling=444,422,420,GRAY,440,411 conversion sampling (default: 444) -v, --version display cli name & version
Convert images using mozjpeg ```