5.7 KiB
Installation
npm install sharp
Prerequisites
- C++11 compatible compiler such as gcc 4.6+ (Node v4+ requires gcc 4.8+), clang 3.0+ or MSVC 2013
- node-gyp
Linux
libvips and its dependencies are fetched and stored within node_modules/sharp/lib
during npm install
.
This involves an automated HTTPS download of approximately 6MB.
Most recent Linux-based operating systems with glibc running on x64 and ARMv6+ CPUs should "just work", e.g.:
- Debian 7, 8
- Ubuntu 12.04, 14.04, 14.10, 15.04, 15.10
- Centos 7
- Fedora 21, 22, 23
- openSUSE 13.2
- Archlinux 2015.06.01
- Raspbian Jessie
- Amazon Linux 2015.03, 2015.09
To use your own version of libvips instead of the provided binaries, make sure it is
at least the version listed under config.libvips
in the package.json
file that it
can be located using pkg-config
. If you are using non-stadard paths (anything other
than /usr
or /usr/local
), you might need to set PKG_CONFIG_PATH
during npm install
and LD_LIBRARY_PATH
at runtime.
You can print the detected vips version using: pkg-config --modversion vips-cpp
This allows the use of newer versions of libvips with older versions of sharp.
For older Linux-based operating systems and 32-bit Intel CPUs,
a system-wide installation of the most suitable version of
libvips and its dependencies can be achieved by running
the following command as a user with sudo
access
(requires curl
and pkg-config
):
curl -s https://raw.githubusercontent.com/lovell/sharp/master/preinstall.sh | sudo bash -
For Linux-based operating systems such as Alpine that use musl libc,
the smaller stack size means libvips' cache should be disabled
via sharp.cache(false)
to avoid a stack overflow.
Beware of Linux OS upgrades that introduce v5.1+ of the g++
compiler due to
changes
in the C++11 ABI.
This module assumes the previous behaviour, which can be enforced by setting the
_GLIBCXX_USE_CXX11_ABI=0
environment variable at libvips' compile time.
Mac OS
libvips must be installed before npm install
is run.
This can be achieved via homebrew:
brew install homebrew/science/vips
For GIF input and WebP output suppport use:
brew install homebrew/science/vips --with-imagemagick --with-webp
A missing or incorrectly configured Xcode Command Line Tools installation
can lead to a
library not found for -ljpeg
error.
If so, please try: xcode-select --install
.
The gettext dependency of libvips
can lead
to a library not found for -lintl
error.
If so, please try brew link gettext --force
.
Windows
libvips and its dependencies are fetched and stored within node_modules\sharp
during npm install
.
This involves an automated HTTPS download of approximately 9MB.
Only 64-bit (x64) node.exe
is supported.
The WebP format is currently unavailable on Windows.
FreeBSD
libvips must be installed before npm install
is run.
This can be achieved via FreshPorts:
cd /usr/ports/graphics/vips/ && make install clean
Heroku
Alessandro Tagliapietra maintains an Heroku buildpack for libvips and its dependencies.
Docker
Marc Bachmann maintains an Ubuntu-based Dockerfile for libvips.
docker pull marcbachmann/libvips
Will Jordan maintains an Alpine-based Dockerfile for libvips.
docker pull wjordan/libvips
AWS Lambda
In order to use sharp on AWS Lambda, you need to create a deployment package. Because sharp
downloads and links libraries for the current platform during npm install
you have to
do this on a system similar to the Lambda Execution Environment. The easiest ways to do this, is to setup a
small t2.micro instance using the AMI ID listed in the previous link, ssh into it as ec2-user
and follow the instructions below.
Install depencies:
sudo yum-config-manager --enable epel
sudo yum install -y nodejs gcc-c++
curl -s https://www.npmjs.com/install.sh | sudo sh
Copy your code and package.json to the instance using scp
and create a deployment package:
cd sharp-lambda-example
npm install
zip -ur9 ../sharp-lambda-example.zip index.js node_modules
You can now download your deployment ZIP using scp
and upload it to Lambda.
Performance Tip: To get the best performance on Lambda choose the largest memory available because this also gives you the most cpu time (a 1536 MB function is 12x faster than a 128 MB function).