Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

jpeg-turbo

sorccu409Apache-2.00.4.0

Limited libjpeg-turbo bindings for Node.js.

jpeg, jpeg-turbo, libjpeg-turbo

readme

node-jpeg-turbo

Build Status npm

node-jpeg-turbo provides minimal libjpeg-turbo bindings for Node.js. It is very, very fast compared to other alternatives, such as node-imagemagick-native or jpeg-js.

Please ask if you need more methods exposed.

Requirements

We use NAN to guarantee maximum v8 API compatibility, so in theory any Node.js or io.js version should work fine. For maximum convenience we also use node-pre-gyp to publish prebuilt binaries for a few common platforms. For example, if you're on OS X and using the latest stable Node, you probably won't need to do a thing.

If you must build from source

First, if you're building from the repo, make sure to init and update submodules or you'll get confusing errors about missing targets when building. We include libjpeg-turbo as a submodule.

git submodule init
git submodule update

(or just use git clone --recursive when cloning the repo)

Due to massive linking pain on Ubuntu, we embed and build libjpeg-turbo directly with node-gyp. Unfortunately this adds an extra requirement, as the build process needs yasm to enable all optimizations. Note that this step is only required for x86 and x86_64 architectures. You don't need yasm if you're building on arm, for example.

Here's how to install yasm:

On OS X

brew install yasm

On Ubuntu 14.04

apt-get install yasm

On Ubuntu 12.04

apt-get install yasm

Important! Ubuntu 12.04 comes with GCC 4.6, which is too old to compile the add-on (and most other modules since Node.js 4.0 was released). More information is available here.

If you really must use this module on Ubuntu 12.04, the following may work:

apt-get install python-software-properties
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get -y install g++-4.8
export CXX=g++-4.8

Remember to export CXX when you npm install.

On Debian

apt-get install yasm

On Alpine Linux

apk add yasm

Others

Search your package manager for yasm.

Installation

Make sure you've got the requirements installed. Then simply install from NPM:

npm install --save jpeg-turbo

API

jpg.bufferSize(options)Number

If you'd like to preallocate a Buffer for jpg.compressSync(), use this method to get the worst-case upper bound. The options argument is fully compatible with the jpg.compressSync() method, so that you can pass the same options to both functions.

  • options is an Object with the following properties:
    • width Required. The width of the image.
    • height Required. The height of the image.
    • subsampling Optional. The subsampling method to use. Defaults to jpg.SAMP_420.
  • Returns The Number of bytes required in a worst-case scenario.
var fs = require('fs')
var jpg = require('jpeg-turbo')

var raw = fs.readFileSync('raw.rgba')

var options = {
  format: jpg.FORMAT_RGBA,
  width: 1080,
  height: 1920,
  subsampling: jpg.SAMP_444,
}

var preallocated = new Buffer(jpg.bufferSize(options))

var encoded = jpg.compressSync(raw, preallocated, options)

jpg.compressSync(raw[, out], options)Buffer

Compresses (i.e. encodes) the raw pixel data into a JPG. This method is not capable of resizing the image.

For efficiency reasons you may choose to encode into a preallocated Buffer. While fast, it has a number of drawbacks. Namely, you'll have to be careful not to reuse the buffer in async processing before processing (e.g. saving, displaying or transmitting) the entire encoded image. Otherwise you risk corrupting the image. Also, it wastes a huge amount of space compared to on-demand allocation.

  • raw is a Buffer with the raw pixel data in options.format.
  • out is an optional preallocated Buffer for the encoded image. The size of the buffer is checked. See jpg.bufferSize() for an example of how to preallocate a sufficient Buffer. If not given, memory is allocated and reallocated as needed, which eliminates most of the wasted space but is slower and lacks consistency with varying source images.
  • options is an Object with the following properties:
    • format Required. The format of the raw pixel data (e.g. jpg.FORMAT_RGBA).
    • width Required. The width of the image.
    • height Required. The height of the image.
    • subsampling Optional. The subsampling method to use. Defaults to jpg.SAMP_420.
    • quality Optional. The desired JPG quality. Defaults to 80.
  • Returns The encoded image as a Buffer. Note that the buffer may actually be a slice of the preallocated Buffer, if given. Be careful not to reuse the preallocated buffer before you've finished processing the encoded image, as it may corrupt the image.
var fs = require('fs')
var jpg = require('jpeg-turbo')

var raw = fs.readFileSync('raw.rgba')

var options = {
  format: jpg.FORMAT_RGBA,
  width: 1080,
  height: 1920,
  subsampling: jpg.SAMP_444,
}

var encoded = jpg.compressSync(raw, options)

See jpg.bufferSize() for an example of preallocated Buffer usage.

jpg.decompressSync(image[, out], options)Object

Decompresses (i.e. decodes) the JPG image into raw pixel data.

  • image is a Buffer with the JPG image data.
  • out is an optional preallocated Buffer for the decoded image. The size of the buffer is checked, and should be at least width * height * bytes_per_pixel or larger. If not given, one is created for you. The only benefit of providing the Buffer yourself is that you can reuse the same buffer between multiple jpg.decompressSync() calls. Note that this can lead to issues with concurrency. See jpg.compressSync() for related discussion.
  • options is an Object with the following properties:
    • format Required. The desired format of the raw pixel data (e.g. jpg.FORMAT_RGBA).
    • out Deprecated. Use the out argument instead.
  • Returns An Object with the following properties:
    • data A Buffer with the raw pixel data.
    • width The width of the image.
    • height The height of the image.
    • subsampling The subsampling method used in the JPG.
    • size Deprecated. Use data.length instead.
    • bpp The number of bytes per pixel.
var fs = require('fs')
var jpg = require('jpeg-turbo')

var image = fs.readFileSync('image.jpg')

var options = {
  format: jpg.FORMAT_RGBA,
}

var decoded = jpg.decompressSync(image, options)

Thanks

License

See LICENSE.

Copyright © Simo Kinnunen. All Rights Reserved.

changelog

node-pre-gyp changelog

0.6.19

  • Add known node version for 4.2.4

0.6.18

  • Add new known node versions for 0.10.x, 0.12.x, 4.x, and 5.x

0.6.17

  • Re-tagged to fix packaging problem of Error: Cannot find module 'isarray'

0.6.16

  • Added known version in crosswalk for 5.1.0.

0.6.15

0.6.14

  • Added node 5.x version

0.6.13

  • Added more known node 4.x versions

0.6.12

  • Added support for Electron. Just pass the --runtime=electron flag when building/installing. Thanks @zcbenz

0.6.11

  • Added known node and io.js versions including more 3.x and 4.x versions

0.6.10

  • Added known node and io.js versions including 3.x and 4.x versions
  • Upgraded tar dep

0.6.9

  • Upgraded rc dep
  • Updated known io.js version: v2.4.0

0.6.8

  • Upgraded semver and rimraf deps
  • Updated known node and io.js versions

0.6.7

0.6.6

  • Updated with known io.js 2.0.0 version

0.6.5

0.6.4

  • Improved support for io.js (@fengmk2)
  • Test coverage improvements (@mikemorris)
  • Fixed support for --dist-url that regressed in 0.6.3

0.6.3

  • Added support for passing raw options to node-gyp using -- separator. Flags passed after the -- to node-pre-gyp configure will be passed directly to gyp while flags passed after the -- will be passed directly to make/visual studio.
  • Added node-pre-gyp configure command to be able to call node-gyp configure directly
  • Fix issue with require validation not working on windows 7 (@edgarsilva)

0.6.2

  • Support for io.js >= v1.0.2
  • Deferred require of request and tar to help speed up command line usage of node-pre-gyp.

0.6.1

  • Fixed bundled tar version

0.6.0

  • BREAKING: node odd releases like v0.11.x now use major.minor.patch for {node_abi} instead of NODE_MODULE_VERSION (#124)
  • Added support for toolset option in versioning. By default is an empty string but --toolset can be passed to publish or install to select alternative binaries that target a custom toolset like C++11. For example to target Visual Studio 2014 modules like node-sqlite3 use --toolset=v140.
  • Added support for --no-rollback option to request that a failed binary test does not remove the binary module leaves it in place.
  • Added support for --update-binary option to request an existing binary be re-installed and the check for a valid local module be skipped.
  • Added support for passing build options from npm through node-pre-gyp to node-gyp: --nodedir, --disturl, --python, and --msvs_version

0.5.31

  • Added support for deducing node_abi for node.js runtime from previous release if the series is even
  • Added support for --target=0.10.33

0.5.30

  • Repackaged with latest bundled deps

0.5.29

  • Added support for semver build.
  • Fixed support for downloading from urls that include +.

0.5.28

  • Now reporting unix style paths only in reveal command

0.5.27

  • Fixed support for auto-detecting s3 bucket name when it contains . - @taavo
  • Fixed support for installing when path contains a ' - @halfdan
  • Ported tests to mocha

0.5.26

  • Fix node-webkit support when --target option is not provided

0.5.25

  • Fix bundling of deps

0.5.24

  • Updated ABI crosswalk to incldue node v0.10.30 and v0.10.31

0.5.23

  • Added reveal command. Pass no options to get all versioning data as json. Pass a second arg to grab a single versioned property value
  • Added support for --silent (shortcut for --loglevel=silent)

0.5.22

  • Fixed node-webkit versioning name (NOTE: node-webkit support still experimental)

0.5.21

  • New package to fix shasum check failed error with v0.5.20

0.5.20

  • Now versioning node-webkit binaries based on major.minor.patch - assuming no compatible ABI across versions (#90)

0.5.19

  • Updated to know about more node-webkit releases

0.5.18

  • Updated to know about more node-webkit releases

0.5.17

  • Updated to know about node v0.10.29 release

0.5.16

0.5.15

  • Fixed installation of windows packages sub directories on unix systems (#84)

0.5.14

  • Finished support for cross building using --target_platform option (#82)
  • Now skipping binary validation on install if target arch/platform do not match the host.
  • Removed multi-arch validing for OS X since it required a FAT node.js binary

0.5.13

  • Fix problem in 0.5.12 whereby the wrong versions of mkdirp and semver where bundled.

0.5.12

  • Improved support for node-webkit (@Mithgol)

0.5.11

  • Updated target versions listing

0.5.10

  • Fixed handling of -debug flag passed directory to node-pre-gyp (#72)
  • Added optional second arg to node_pre_gyp.find to customize the default versioning options used to locate the runtime binary
  • Failed install due to testbinary check failure no longer leaves behind binary (#70)

0.5.9

  • Fixed regression in testbinary command causing installs to fail on windows with 0.5.7 (#60)

0.5.8

  • Started bundling deps

0.5.7

  • Fixed the testbinary check, which is used to determine whether to re-download or source compile, to work even in complex dependency situations (#63)
  • Exposed the internal testbinary command in node-pre-gyp command line tool
  • Fixed minor bug so that fallback_to_build option is always respected

0.5.6

  • Added support for versioning on the name value in package.json (#57).
  • Moved to using streams for reading tarball when publishing (#52)

0.5.5

  • Improved binary validation that also now works with node-webkit (@Mithgol)
  • Upgraded test apps to work with node v0.11.x
  • Improved test coverage

0.5.4

  • No longer depends on external install of node-gyp for compiling builds.

0.5.3

  • Reverted fix for debian/nodejs since it broke windows (#45)

0.5.2

  • Support for debian systems where the node binary is named nodejs (#45)
  • Added bin/node-pre-gyp.cmd to be able to run command on windows locally (npm creates an .npm automatically when globally installed)
  • Updated abi-crosswalk with node v0.10.26 entry.

0.5.1

  • Various minor bug fixes, several improving windows support for publishing.

0.5.0

  • Changed property names in binary object: now required are module_name, module_path, and host.
  • Now module_path supports versioning, which allows developers to opt-in to using a versioned install path (#18).
  • Added remote_path which also supports versioning.
  • Changed remote_uri to host.

0.4.2

  • Added support for --target flag to request cross-compile against a specific node/node-webkit version.
  • Added preliminary support for node-webkit
  • Fixed support for --target_arch option being respected in all cases.

0.4.1

  • Fixed exception when only stderr is available in binary test (@bendi / #31)

0.4.0

  • Enforce only https: based remote publishing access.
  • Added node-pre-gyp info command to display listing of published binaries
  • Added support for changing the directory node-pre-gyp should build in with the -C/--directory option.
  • Added support for S3 prefixes.

0.3.1

  • Added unpublish command.
  • Fixed module path construction in tests.
  • Added ability to disable falling back to build behavior via npm install --fallback-to-build=false which overrides setting in a depedencies package.json install target.

0.3.0

  • Support for packaging all files in module_path directory - see app4 for example
  • Added testpackage command.
  • Changed clean command to only delete .node not entire build directory since node-gyp will handle that.
  • .node modules must be in a folder of there own since tar-pack will remove everything when it unpacks.