From 8012733a52c77d05ff52f58106fe53948d97be9d Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Sun, 22 Nov 2015 20:58:38 +0000 Subject: [PATCH] Expose libvips+deps versions attribute Add versions.json for Linux packaging Bump vips-dev Windows version for latest libpng --- docs/api.md | 23 +++++++++++++ index.js | 41 ++++++++++++---------- packaging/lin/Dockerfile | 74 ++++++++++++++++++++++++++++++---------- packaging/win/Dockerfile | 4 +-- test/unit/threshold.js | 12 +++++++ test/unit/util.js | 7 ++++ 6 files changed, 123 insertions(+), 38 deletions(-) diff --git a/docs/api.md b/docs/api.md index 83b177dc..637a6e8e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -569,6 +569,29 @@ sharp.queue.on('change', function(queueLength) { }); ``` +#### versions + +An Object containing the version numbers of libvips and, on Linux, its dependencies. + +```javascript +> console.log(sharp.versions); + +{ zlib: '1.2.8', + ffi: '3.2.1', + glib: '2.46.2', + xml: '2.9.2', + gsf: '1.14.34', + exif: '0.6.21', + jpeg: '1.4.2', + png: '1.6.19', + lcms: '2.7', + webp: '0.4.4', + tiff: '4.0.6', + magick: '6.9.2-6', + orc: '0.4.24', + vips: '8.1.1' } +``` + ### Utilities #### sharp.cache([memory], [items]) diff --git a/index.js b/index.js index 76a6fb18..c0cac547 100644 --- a/index.js +++ b/index.js @@ -10,19 +10,31 @@ var color = require('color'); var BluebirdPromise = require('bluebird'); var sharp = require('./build/Release/sharp'); -var libvipsVersion = sharp.libvipsVersion(); -var libvipsVersionMin = require('./package.json').config.libvips; -if (semver.lt(libvipsVersion, libvipsVersionMin)) { - throw new Error('Found libvips ' + libvipsVersion + ' but require at least ' + libvipsVersionMin); -} +// Versioning +var versions = { + vips: sharp.libvipsVersion() +}; +(function() { + // Does libvips meet minimum requirement? + var libvipsVersionMin = require('./package.json').config.libvips; + if (semver.lt(versions.vips, libvipsVersionMin)) { + throw new Error('Found libvips ' + versions.vips + ' but require at least ' + libvipsVersionMin); + } + // Include versions of dependencies, if present + try { + versions = require('./lib/versions.json'); + } catch (err) {} +})(); +// Limits var maximum = { width: 0x3FFF, height: 0x3FFF, pixels: Math.pow(0x3FFF, 2) }; +// Constructor-factory var Sharp = function(input) { if (!(this instanceof Sharp)) { return new Sharp(input); @@ -116,6 +128,11 @@ module.exports.queue = new events.EventEmitter(); */ module.exports.format = sharp.format(); +/* + Version numbers of libvips and its dependencies +*/ +module.exports.versions = versions; + /* Handle incoming chunk on Writable Stream */ @@ -652,12 +669,7 @@ Sharp.prototype.webp = function() { Force raw, uint8 output */ Sharp.prototype.raw = function() { - var supportsRawOutput = module.exports.format.raw.output; - if (supportsRawOutput.file || supportsRawOutput.buffer || supportsRawOutput.stream) { - this.options.output = '__raw'; - } else { - console.error('Raw output requires libvips 7.42.0+'); - } + this.options.output = '__raw'; return this; }; @@ -851,10 +863,3 @@ module.exports.concurrency = function(concurrency) { module.exports.counters = function() { return sharp.counters(); }; - -/* - Get the version of the libvips library -*/ -module.exports.libvipsVersion = function() { - return libvipsVersion; -}; diff --git a/packaging/lin/Dockerfile b/packaging/lin/Dockerfile index 343fce2a..61cff49e 100644 --- a/packaging/lin/Dockerfile +++ b/packaging/lin/Dockerfile @@ -1,87 +1,105 @@ FROM debian:wheezy MAINTAINER Lovell Fuller +# Build dependencies RUN apt-get update && apt-get install -y build-essential autoconf libtool nasm gtk-doc-tools texinfo +# Working directories ENV DEPS /deps ENV TARGET /target RUN mkdir ${DEPS} && mkdir ${TARGET} +# Common build paths and flags ENV PKG_CONFIG_PATH ${PKG_CONFIG_PATH}:${TARGET}/lib/pkgconfig ENV PATH ${PATH}:${TARGET}/bin - ENV CPPFLAGS -I${TARGET}/include ENV LDFLAGS -L${TARGET}/lib +# Dependency version numbers +ENV VERSION_ZLIB 1.2.8 +ENV VERSION_FFI 3.2.1 +ENV VERSION_GLIB 2.46.2 +ENV VERSION_XML2 2.9.2 +ENV VERSION_GSF 1.14.34 +ENV VERSION_EXIF 0.6.21 +ENV VERSION_JPEG 1.4.2 +ENV VERSION_PNG16 1.6.19 +ENV VERSION_LCMS2 2.7 +ENV VERSION_WEBP 0.4.4 +ENV VERSION_TIFF 4.0.6 +ENV VERSION_MAGICK 6.9.2-6 +ENV VERSION_ORC 0.4.24 +ENV VERSION_VIPS 8.1.1 + RUN mkdir ${DEPS}/zlib -RUN curl -Ls http://zlib.net/zlib-1.2.8.tar.xz | tar xJC ${DEPS}/zlib --strip-components=1 +RUN curl -Ls http://zlib.net/zlib-${VERSION_ZLIB}.tar.xz | tar xJC ${DEPS}/zlib --strip-components=1 WORKDIR ${DEPS}/zlib RUN ./configure --prefix=${TARGET} && make install RUN rm ${TARGET}/lib/libz.a RUN mkdir ${DEPS}/ffi -RUN curl -Ls ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz | tar xzC ${DEPS}/ffi --strip-components=1 +RUN curl -Ls ftp://sourceware.org/pub/libffi/libffi-${VERSION_FFI}.tar.gz | tar xzC ${DEPS}/ffi --strip-components=1 WORKDIR ${DEPS}/ffi RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --disable-builddir && make install-strip RUN mkdir ${DEPS}/glib -RUN curl -Ls http://ftp.gnome.org/pub/gnome/sources/glib/2.46/glib-2.46.2.tar.xz | tar xJC ${DEPS}/glib --strip-components=1 +RUN curl -Ls http://ftp.gnome.org/pub/gnome/sources/glib/2.46/glib-${VERSION_GLIB}.tar.xz | tar xJC ${DEPS}/glib --strip-components=1 WORKDIR ${DEPS}/glib RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN mkdir ${DEPS}/xml2 -RUN curl -Ls http://xmlsoft.org/sources/libxml2-2.9.2.tar.gz | tar xzC ${DEPS}/xml2 --strip-components=1 +RUN curl -Ls http://xmlsoft.org/sources/libxml2-${VERSION_XML2}.tar.gz | tar xzC ${DEPS}/xml2 --strip-components=1 WORKDIR ${DEPS}/xml2 RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --without-python --with-zlib=${TARGET} && make install-strip RUN mkdir ${DEPS}/gsf -RUN curl -Ls http://ftp.gnome.org/pub/GNOME/sources/libgsf/1.14/libgsf-1.14.34.tar.xz | tar xJC ${DEPS}/gsf --strip-components=1 +RUN curl -Ls http://ftp.gnome.org/pub/GNOME/sources/libgsf/1.14/libgsf-${VERSION_GSF}.tar.xz | tar xJC ${DEPS}/gsf --strip-components=1 WORKDIR ${DEPS}/gsf RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN mkdir ${DEPS}/exif -RUN curl -Ls http://kent.dl.sourceforge.net/project/libexif/libexif/0.6.21/libexif-0.6.21.tar.bz2 | tar xjC ${DEPS}/exif --strip-components=1 +RUN curl -Ls http://kent.dl.sourceforge.net/project/libexif/libexif/${VERSION_EXIF}/libexif-${VERSION_EXIF}.tar.bz2 | tar xjC ${DEPS}/exif --strip-components=1 WORKDIR ${DEPS}/exif RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN mkdir ${DEPS}/jpeg -RUN curl -Ls http://kent.dl.sourceforge.net/project/libjpeg-turbo/1.4.2/libjpeg-turbo-1.4.2.tar.gz | tar xzC ${DEPS}/jpeg --strip-components=1 +RUN curl -Ls http://kent.dl.sourceforge.net/project/libjpeg-turbo/${VERSION_JPEG}/libjpeg-turbo-${VERSION_JPEG}.tar.gz | tar xzC ${DEPS}/jpeg --strip-components=1 WORKDIR ${DEPS}/jpeg RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --with-jpeg8 --without-turbojpeg && make install-strip -RUN mkdir ${DEPS}/png -RUN curl -Ls http://kent.dl.sourceforge.net/project/libpng/libpng16/1.6.19/libpng-1.6.19.tar.xz | tar xJC ${DEPS}/png --strip-components=1 -WORKDIR ${DEPS}/png +RUN mkdir ${DEPS}/png16 +RUN curl -Ls http://kent.dl.sourceforge.net/project/libpng/libpng16/${VERSION_PNG16}/libpng-${VERSION_PNG16}.tar.xz | tar xJC ${DEPS}/png16 --strip-components=1 +WORKDIR ${DEPS}/png16 RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN mkdir ${DEPS}/lcms2 -RUN curl -Ls http://kent.dl.sourceforge.net/project/lcms/lcms/2.7/lcms2-2.7.tar.gz | tar xzC ${DEPS}/lcms2 --strip-components=1 +RUN curl -Ls http://kent.dl.sourceforge.net/project/lcms/lcms/${VERSION_LCMS2}/lcms2-${VERSION_LCMS2}.tar.gz | tar xzC ${DEPS}/lcms2 --strip-components=1 WORKDIR ${DEPS}/lcms2 RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN mkdir ${DEPS}/webp -RUN curl -Ls http://downloads.webmproject.org/releases/webp/libwebp-0.4.4.tar.gz | tar xzC ${DEPS}/webp --strip-components=1 +RUN curl -Ls http://downloads.webmproject.org/releases/webp/libwebp-${VERSION_WEBP}.tar.gz | tar xzC ${DEPS}/webp --strip-components=1 WORKDIR ${DEPS}/webp RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN mkdir ${DEPS}/tiff -RUN curl -Ls http://download.osgeo.org/libtiff/tiff-4.0.6.tar.gz /deps/tiff.tar.gz | tar xzC ${DEPS}/tiff --strip-components=1 +RUN curl -Ls http://download.osgeo.org/libtiff/tiff-${VERSION_TIFF}.tar.gz /deps/tiff.tar.gz | tar xzC ${DEPS}/tiff --strip-components=1 WORKDIR ${DEPS}/tiff RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN rm ${TARGET}/lib/libtiffxx* RUN mkdir ${DEPS}/magick -RUN curl -Ls http://www.imagemagick.org/download/releases/ImageMagick-6.9.2-6.tar.xz | tar xJC ${DEPS}/magick --strip-components=1 +RUN curl -Ls http://www.imagemagick.org/download/releases/ImageMagick-${VERSION_MAGICK}.tar.xz | tar xJC ${DEPS}/magick --strip-components=1 WORKDIR ${DEPS}/magick RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --without-magick-plus-plus && make install-strip RUN mkdir ${DEPS}/orc -RUN curl -Ls http://gstreamer.freedesktop.org/data/src/orc/orc-0.4.24.tar.xz | tar xJC ${DEPS}/orc --strip-components=1 +RUN curl -Ls http://gstreamer.freedesktop.org/data/src/orc/orc-${VERSION_ORC}.tar.xz | tar xJC ${DEPS}/orc --strip-components=1 WORKDIR ${DEPS}/orc RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking && make install-strip RUN mkdir ${DEPS}/vips -RUN curl -Ls http://www.vips.ecs.soton.ac.uk/supported/8.1/vips-8.1.1.tar.gz | tar xzC ${DEPS}/vips --strip-components=1 +RUN curl -Ls http://www.vips.ecs.soton.ac.uk/supported/8.1/vips-${VERSION_VIPS}.tar.gz | tar xzC ${DEPS}/vips --strip-components=1 WORKDIR ${DEPS}/vips RUN ./configure --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking \ --disable-debug --disable-introspection --without-python --without-fftw \ @@ -95,5 +113,25 @@ RUN rm -rf vips/vipsc++.h vips/vipscpp.h vips/V*.h WORKDIR ${TARGET}/lib RUN rm -rf pkgconfig .libs *.la libvipsCC* libvips-cpp.* +# Create JSON file of version numbers WORKDIR ${TARGET} -RUN GZIP=-9 tar czf /libvips-8.1.1-lin.tar.gz include lib +RUN echo "{\n\ + \"zlib\": \"${VERSION_ZLIB}\",\n\ + \"ffi\": \"${VERSION_FFI}\",\n\ + \"glib\": \"${VERSION_GLIB}\",\n\ + \"xml\": \"${VERSION_XML2}\",\n\ + \"gsf\": \"${VERSION_GSF}\",\n\ + \"exif\": \"${VERSION_EXIF}\",\n\ + \"jpeg\": \"${VERSION_JPEG}\",\n\ + \"png\": \"${VERSION_PNG16}\",\n\ + \"lcms\": \"${VERSION_LCMS2}\",\n\ + \"webp\": \"${VERSION_WEBP}\",\n\ + \"tiff\": \"${VERSION_TIFF}\",\n\ + \"magick\": \"${VERSION_MAGICK}\",\n\ + \"orc\": \"${VERSION_ORC}\",\n\ + \"vips\": \"${VERSION_VIPS}\"\n\ +}" >lib/versions.json + +# Create .tar.gz +WORKDIR ${TARGET} +RUN GZIP=-9 tar czf /libvips-${VERSION_VIPS}-lin.tar.gz include lib diff --git a/packaging/win/Dockerfile b/packaging/win/Dockerfile index d2c3c52e..e1eb1105 100644 --- a/packaging/win/Dockerfile +++ b/packaging/win/Dockerfile @@ -6,8 +6,8 @@ RUN apt-get update && apt-get install -y curl zip # Fetch and unzip RUN mkdir /vips WORKDIR /vips -RUN curl -O http://www.vips.ecs.soton.ac.uk/supported/8.1/win32/vips-dev-w64-8.1.1-2.zip -RUN unzip vips-dev-w64-8.1.1-2.zip +RUN curl -O http://www.vips.ecs.soton.ac.uk/supported/8.1/win32/vips-dev-w64-8.1.1-3.zip +RUN unzip vips-dev-w64-8.1.1-3.zip # Clean and zip WORKDIR /vips/vips-dev-8.1.1 diff --git a/test/unit/threshold.js b/test/unit/threshold.js index 61a62a32..56d674e6 100644 --- a/test/unit/threshold.js +++ b/test/unit/threshold.js @@ -44,6 +44,18 @@ describe('Threshold', function() { }); }); + it('threshold true (=128)', function(done) { + sharp(fixtures.inputJpg) + .resize(320, 240) + .threshold(true) + .toBuffer(function(err, data, info) { + assert.strictEqual('jpeg', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('threshold-128.jpg'), data, done); + }); + }); + it('threshold default jpeg', function(done) { sharp(fixtures.inputJpg) .resize(320, 240) diff --git a/test/unit/util.js b/test/unit/util.js index dae2f0f2..d3b15428 100644 --- a/test/unit/util.js +++ b/test/unit/util.js @@ -72,4 +72,11 @@ describe('Utilities', function() { }); }); + describe('Versions', function() { + it('Contains expected attributes', function() { + assert.strictEqual('object', typeof sharp.versions); + assert.strictEqual('string', typeof sharp.versions.vips); + }); + }); + });