diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 00000000..81f7b37b --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,46 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + env: + DEBUG: "gm*" + + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + node-version: [14.x, 16.x, 18.x] + # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ + + steps: + - name: Install GraphicsMagic and Imagemagick on Ubuntu + if: contains(matrix.os, 'ubuntu') + run: sudo apt-get install -y imagemagick graphicsmagick + - name: Install GraphicsMagic and Imagemagick on Windows + if: contains(matrix.os, 'windows') + run: choco install -y imagemagick graphicsmagick + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - run: npm i + - name: Run tests on Windows + if: contains(matrix.os, 'windows') + shell: cmd + run: | + call refreshenv + npm test + - name: Run tests on Ubuntu + if: contains(matrix.os, 'ubuntu') + run: npm test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0d04d004..cc069782 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store node_modules +package-lock.json examples/imgs/* !examples/imgs/original.jpg !examples/imgs/original.png @@ -10,4 +11,4 @@ examples/imgs/* !examples/imgs/orientation/*\d.jpg !examples/imgs/orientation/*.correct.jpg *.sw* -.idea \ No newline at end of file +.idea diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f312f797..00000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -before_install: - - sudo apt-get update - - sudo apt-get install imagemagick graphicsmagick -language: node_js -node_js: - - "0.10" - - "0.12" - - "iojs-v2" diff --git a/History.md b/History.md index c7e278e6..66499e0a 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,54 @@ -1.19 / 2015-09-16 +1.25.0 / 2022-09-21 + +* fixed: windows support #846, #774, #594, #524, #528, #559, #652, #682 [piotr-cz](https://github.com/piotr-cz) +* docs; improvements from #821 [agokhale](https://github.com/agokhale) +* docs; improvements #801 [aarongarciah](https://github.com/aarongarciah) + +1.24.0 / 2022-09-18 + +* fixed: infering format of buffered or streamed ico files #429 freund17 +* fixed; preserve color info duing autoOrient() #714, #844 reco +* tests; switch to Github Actions +* docs; fix links #834 delesseps +* docs; clarify install directions #689 PatrykMiszczak +* refactor; clean up compare.js #788 LongTengDao + +1.23.1 / 2017-12-27 + + * fixed: use debug > 2.6.9 because of security issue #685 danez + * tests; add nsp check + * tests; get tests passing on OSX + +1.23.0 / 2016-08-03 + + * fixed; webpack support #547 sean-shirazi + * fixed; windows support - use cross-spawn to spawn processes #537 bdukes + * added; allow thumbnail to accept the same options as resize #527 Sebmaster + * added; dispose support #487 dlwr + * docs; add example of loading image from URL #544 wahengchang + * docs; Fix a link in README.md #532 clbn + * travis; update travis versions #551 amilajack + +1.22.0 / 2016-04-07 + + * fixed; identity parser: support multi-value keys by creating an array #508 #509 [emaniacs](https://github.com/emaniacs) + * fixed; error handling if gm is not installed #499 [aeo3](https://github.com/aeo3) + * fixed; highlightColor typo in compare #504 [DanielHudson](https://github.com/DanielHudson) + * docs; Fix typo #475 [rodrigoalviani](https://github.com/rodrigoalviani) + +1.21.1 / 2015-10-26 + +* fixed: Fixed #465 hard coded gm binary, also fixed issues with compare and fixed tests so they will fail on subsequent runs when they should do [rwky](https://github.com/rwky) + +1.21.0 / 2015-10-26 **contains security fix** + +* fixed: gm.compare fails to escape arguments properly (Reported by Brendan Scarvell) [rwky](https://github.com/rwky) + +1.20.0 / 2015-09-23 + +* changed: Reverted "Add format inference from filename for buffers/streams" due to errors #448 + +1.19.0 / 2015-09-16 * changed: Added error to notify about image magick not supporting minify [encima](https://github.com/encima) * changed: Refactored orientation getter to use faster identify call [lbeschastny](https://github.com/lbeschastny) diff --git a/Makefile b/Makefile deleted file mode 100644 index c53cba86..00000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ - -test: - @node test/ --integration $(TESTS) - -test-unit: - @node test/ $(TESTS) - -.PHONY: test test-unit diff --git a/README.md b/README.md index aed0ff9f..e16fdc29 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,6 @@ First download and install [GraphicsMagick](http://www.graphicsmagick.org/) or [ brew install imagemagick brew install graphicsmagick -If you want WebP support with ImageMagick, you must add the WebP option: - - brew install imagemagick --with-webp - then either use npm: npm install gm @@ -28,18 +24,30 @@ or clone the repo: ## Use ImageMagick instead of gm -Subclass `gm` to enable ImageMagick +Subclass `gm` to enable [ImageMagick 7+](https://imagemagick.org/script/porting.php) ```js -var fs = require('fs') - , gm = require('gm').subClass({imageMagick: true}); +const fs = require('fs') +const gm = require('gm').subClass({ imageMagick: '7+' }); +``` -// resize and remove EXIF profile data -gm('/path/to/my/img.jpg') -.resize(240, 240) -... +Or, to enable ImageMagick legacy mode (for ImageMagick version < 7) + +```js +const fs = require('fs') +const gm = require('gm').subClass({ imageMagick: true }); ``` +## Specify the executable path + +Optionally specify the path to the executable. + +```js +const fs = require('fs') +const gm = require('gm').subClass({ + appPath: String.raw`C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe` +}); +``` ## Basic Usage @@ -138,6 +146,18 @@ gm(readStream, 'img.jpg') if (!err) console.log('done'); }); + +// passing a downloadable image by url + +var request = require('request'); +var url = "www.abc.com/pic.jpg" + +gm(request(url)) +.write('/path/to/reformat.png', function (err) { + if (!err) console.log('done'); +}); + + // can also stream output to a ReadableStream // (can be piped to a local file or remote server) gm('/path/to/my/img.jpg') @@ -159,12 +179,12 @@ gm('/path/to/my/img.jpg') // gm will provide image data in that format gm('/path/to/my/img.jpg') .stream('png', function (err, stdout, stderr) { - var writeStream = fs.createWriteStream('/path/to/my/reformated.png'); + var writeStream = fs.createWriteStream('/path/to/my/reformatted.png'); stdout.pipe(writeStream); }); // or without the callback -var writeStream = fs.createWriteStream('/path/to/my/reformated.png'); +var writeStream = fs.createWriteStream('/path/to/my/reformatted.png'); gm('/path/to/my/img.jpg') .stream('png') .pipe(writeStream); @@ -312,214 +332,214 @@ The links below refer to an older version of gm but everything should still work ## Methods - getters - - [size](http://aheckmann.github.com/gm/docs.html#getters) - returns the size (WxH) of the image - - [orientation](http://aheckmann.github.com/gm/docs.html#orientation) - returns the EXIF orientation of the image - - [format](http://aheckmann.github.com/gm/docs.html#getters) - returns the image format (gif, jpeg, png, etc) - - [depth](http://aheckmann.github.com/gm/docs.html#getters) - returns the image color depth - - [color](http://aheckmann.github.com/gm/docs.html#getters) - returns the number of colors - - [res](http://aheckmann.github.com/gm/docs.html#getters) - returns the image resolution - - [filesize](http://aheckmann.github.com/gm/docs.html#getters) - returns image filesize - - [identify](http://aheckmann.github.com/gm/docs.html#getters) - returns all image data available. Takes an optional format string. + - [size](http://aheckmann.github.io/gm/docs.html#getters) - returns the size (WxH) of the image + - [orientation](http://aheckmann.github.io/gm/docs.html#getters) - returns the EXIF orientation of the image + - [format](http://aheckmann.github.io/gm/docs.html#getters) - returns the image format (gif, jpeg, png, etc) + - [depth](http://aheckmann.github.io/gm/docs.html#getters) - returns the image color depth + - [color](http://aheckmann.github.io/gm/docs.html#getters) - returns the number of colors + - [res](http://aheckmann.github.io/gm/docs.html#getters) - returns the image resolution + - [filesize](http://aheckmann.github.io/gm/docs.html#getters) - returns image filesize + - [identify](http://aheckmann.github.io/gm/docs.html#getters) - returns all image data available. Takes an optional format string. - manipulation - - [adjoin](http://aheckmann.github.com/gm/docs.html#adjoin) - - [affine](http://aheckmann.github.com/gm/docs.html#affine) - - [antialias](http://aheckmann.github.com/gm/docs.html#antialias) - - [append](http://aheckmann.github.com/gm/docs.html#append) - - [authenticate](http://aheckmann.github.com/gm/docs.html#authenticate) - - [autoOrient](http://aheckmann.github.com/gm/docs.html#autoOrient) - - [average](http://aheckmann.github.com/gm/docs.html#average) - - [backdrop](http://aheckmann.github.com/gm/docs.html#backdrop) - - [bitdepth](http://aheckmann.github.com/gm/docs.html#bitdepth) - - [blackThreshold](http://aheckmann.github.com/gm/docs.html#blackThreshold) - - [bluePrimary](http://aheckmann.github.com/gm/docs.html#bluePrimary) - - [blur](http://aheckmann.github.com/gm/docs.html#blur) - - [border](http://aheckmann.github.com/gm/docs.html#border) - - [borderColor](http://aheckmann.github.com/gm/docs.html#borderColor) - - [box](http://aheckmann.github.com/gm/docs.html#box) - - [channel](http://aheckmann.github.com/gm/docs.html#channel) - - [charcoal](http://aheckmann.github.com/gm/docs.html#charcoal) - - [chop](http://aheckmann.github.com/gm/docs.html#chop) - - [clip](http://aheckmann.github.com/gm/docs.html#clip) - - [coalesce](http://aheckmann.github.com/gm/docs.html#coalesce) - - [colors](http://aheckmann.github.com/gm/docs.html#colors) - - [colorize](http://aheckmann.github.com/gm/docs.html#colorize) - - [colorMap](http://aheckmann.github.com/gm/docs.html#colorMap) - - [colorspace](http://aheckmann.github.com/gm/docs.html#colorspace) - - [comment](http://aheckmann.github.com/gm/docs.html#comment) - - [compose](http://aheckmann.github.com/gm/docs.html#compose) - - [compress](http://aheckmann.github.com/gm/docs.html#compress) - - [contrast](http://aheckmann.github.com/gm/docs.html#contrast) - - [convolve](http://aheckmann.github.com/gm/docs.html#convolve) - - [createDirectories](http://aheckmann.github.com/gm/docs.html#createDirectories) - - [crop](http://aheckmann.github.com/gm/docs.html#crop) - - [cycle](http://aheckmann.github.com/gm/docs.html#cycle) - - [deconstruct](http://aheckmann.github.com/gm/docs.html#deconstruct) - - [delay](http://aheckmann.github.com/gm/docs.html#delay) - - [define](http://aheckmann.github.com/gm/docs.html#define) - - [density](http://aheckmann.github.com/gm/docs.html#density) - - [despeckle](http://aheckmann.github.com/gm/docs.html#despeckle) - - [dither](http://aheckmann.github.com/gm/docs.html#dither) - - [displace](http://aheckmann.github.com/gm/docs.html#dither) - - [display](http://aheckmann.github.com/gm/docs.html#display) - - [dispose](http://aheckmann.github.com/gm/docs.html#dispose) - - [dissolve](http://aheckmann.github.com/gm/docs.html#dissolve) - - [edge](http://aheckmann.github.com/gm/docs.html#edge) - - [emboss](http://aheckmann.github.com/gm/docs.html#emboss) - - [encoding](http://aheckmann.github.com/gm/docs.html#encoding) - - [enhance](http://aheckmann.github.com/gm/docs.html#enhance) - - [endian](http://aheckmann.github.com/gm/docs.html#endian) - - [equalize](http://aheckmann.github.com/gm/docs.html#equalize) - - [extent](http://aheckmann.github.com/gm/docs.html#extent) - - [file](http://aheckmann.github.com/gm/docs.html#file) - - [filter](http://aheckmann.github.com/gm/docs.html#filter) - - [flatten](http://aheckmann.github.com/gm/docs.html#flatten) - - [flip](http://aheckmann.github.com/gm/docs.html#flip) - - [flop](http://aheckmann.github.com/gm/docs.html#flop) - - [foreground](http://aheckmann.github.com/gm/docs.html#foreground) - - [frame](http://aheckmann.github.com/gm/docs.html#frame) - - [fuzz](http://aheckmann.github.com/gm/docs.html#fuzz) - - [gamma](http://aheckmann.github.com/gm/docs.html#gamma) - - [gaussian](http://aheckmann.github.com/gm/docs.html#gaussian) - - [geometry](http://aheckmann.github.com/gm/docs.html#geometry) - - [gravity](http://aheckmann.github.com/gm/docs.html#gravity) - - [greenPrimary](http://aheckmann.github.com/gm/docs.html#greenPrimary) - - [highlightColor](http://aheckmann.github.com/gm/docs.html#highlightColor) - - [highlightStyle](http://aheckmann.github.com/gm/docs.html#highlightStyle) - - [iconGeometry](http://aheckmann.github.com/gm/docs.html#iconGeometry) - - [implode](http://aheckmann.github.com/gm/docs.html#implode) - - [intent](http://aheckmann.github.com/gm/docs.html#intent) - - [interlace](http://aheckmann.github.com/gm/docs.html#interlace) - - [label](http://aheckmann.github.com/gm/docs.html#label) - - [lat](http://aheckmann.github.com/gm/docs.html#lat) - - [level](http://aheckmann.github.com/gm/docs.html#level) - - [list](http://aheckmann.github.com/gm/docs.html#list) - - [limit](http://aheckmann.github.com/gm/docs.html#limit) - - [log](http://aheckmann.github.com/gm/docs.html#log) - - [loop](http://aheckmann.github.com/gm/docs.html#loop) - - [lower](http://aheckmann.github.com/gm/docs.html#lower) - - [magnify](http://aheckmann.github.com/gm/docs.html#magnify) - - [map](http://aheckmann.github.com/gm/docs.html#map) - - [matte](http://aheckmann.github.com/gm/docs.html#matte) - - [matteColor](http://aheckmann.github.com/gm/docs.html#matteColor) - - [mask](http://aheckmann.github.com/gm/docs.html#mask) - - [maximumError](http://aheckmann.github.com/gm/docs.html#maximumError) - - [median](http://aheckmann.github.com/gm/docs.html#median) - - [minify](http://aheckmann.github.com/gm/docs.html#minify) - - [mode](http://aheckmann.github.com/gm/docs.html#mode) - - [modulate](http://aheckmann.github.com/gm/docs.html#modulate) - - [monitor](http://aheckmann.github.com/gm/docs.html#monitor) - - [monochrome](http://aheckmann.github.com/gm/docs.html#monochrome) - - [morph](http://aheckmann.github.com/gm/docs.html#morph) - - [mosaic](http://aheckmann.github.com/gm/docs.html#mosaic) - - [motionBlur](http://aheckmann.github.com/gm/docs.html#motionBlur) - - [name](http://aheckmann.github.com/gm/docs.html#name) - - [negative](http://aheckmann.github.com/gm/docs.html#negative) - - [noise](http://aheckmann.github.com/gm/docs.html#noise) - - [noop](http://aheckmann.github.com/gm/docs.html#noop) - - [normalize](http://aheckmann.github.com/gm/docs.html#normalize) - - [noProfile](http://aheckmann.github.com/gm/docs.html#profile) - - [opaque](http://aheckmann.github.com/gm/docs.html#opaque) - - [operator](http://aheckmann.github.com/gm/docs.html#operator) - - [orderedDither](http://aheckmann.github.com/gm/docs.html#orderedDither) - - [outputDirectory](http://aheckmann.github.com/gm/docs.html#outputDirectory) - - [paint](http://aheckmann.github.com/gm/docs.html#paint) - - [page](http://aheckmann.github.com/gm/docs.html#page) - - [pause](http://aheckmann.github.com/gm/docs.html#pause) - - [pen](http://aheckmann.github.com/gm/docs.html#pen) - - [ping](http://aheckmann.github.com/gm/docs.html#ping) - - [pointSize](http://aheckmann.github.com/gm/docs.html#pointSize) - - [preview](http://aheckmann.github.com/gm/docs.html#preview) - - [process](http://aheckmann.github.com/gm/docs.html#process) - - [profile](http://aheckmann.github.com/gm/docs.html#profile) - - [progress](http://aheckmann.github.com/gm/docs.html#progress) - - [quality](http://aheckmann.github.com/gm/docs.html#quality) - - [raise](http://aheckmann.github.com/gm/docs.html#raise) - - [rawSize](http://aheckmann.github.com/gm/docs.html#rawSize) - - [randomThreshold](http://aheckmann.github.com/gm/docs.html#randomThreshold) - - [recolor](http://aheckmann.github.com/gm/docs.html#recolor) - - [redPrimary](http://aheckmann.github.com/gm/docs.html#redPrimary) - - [region](http://aheckmann.github.com/gm/docs.html#region) - - [remote](http://aheckmann.github.com/gm/docs.html#remote) - - [render](http://aheckmann.github.com/gm/docs.html#render) - - [repage](http://aheckmann.github.com/gm/docs.html#repage) - - [resample](http://aheckmann.github.com/gm/docs.html#resample) - - [resize](http://aheckmann.github.com/gm/docs.html#resize) - - [roll](http://aheckmann.github.com/gm/docs.html#roll) - - [rotate](http://aheckmann.github.com/gm/docs.html#rotate) - - [sample](http://aheckmann.github.com/gm/docs.html#sample) - - [samplingFactor](http://aheckmann.github.com/gm/docs.html#samplingFactor) - - [scale](http://aheckmann.github.com/gm/docs.html#scale) - - [scene](http://aheckmann.github.com/gm/docs.html#scene) - - [scenes](http://aheckmann.github.com/gm/docs.html#scenes) - - [screen](http://aheckmann.github.com/gm/docs.html#screen) - - [segment](http://aheckmann.github.com/gm/docs.html#segment) - - [sepia](http://aheckmann.github.com/gm/docs.html#sepia) - - [set](http://aheckmann.github.com/gm/docs.html#set) - - [setFormat](http://aheckmann.github.com/gm/docs.html#setformat) - - [shade](http://aheckmann.github.com/gm/docs.html#shade) - - [shadow](http://aheckmann.github.com/gm/docs.html#shadow) - - [sharedMemory](http://aheckmann.github.com/gm/docs.html#sharedMemory) - - [sharpen](http://aheckmann.github.com/gm/docs.html#sharpen) - - [shave](http://aheckmann.github.com/gm/docs.html#shave) - - [shear](http://aheckmann.github.com/gm/docs.html#shear) - - [silent](http://aheckmann.github.com/gm/docs.html#silent) - - [solarize](http://aheckmann.github.com/gm/docs.html#solarize) - - [snaps](http://aheckmann.github.com/gm/docs.html#snaps) - - [stegano](http://aheckmann.github.com/gm/docs.html#stegano) - - [stereo](http://aheckmann.github.com/gm/docs.html#stereo) - - [strip](http://aheckmann.github.com/gm/docs.html#strip) _imagemagick only_ - - [spread](http://aheckmann.github.com/gm/docs.html#spread) - - [swirl](http://aheckmann.github.com/gm/docs.html#swirl) - - [textFont](http://aheckmann.github.com/gm/docs.html#textFont) - - [texture](http://aheckmann.github.com/gm/docs.html#texture) - - [threshold](http://aheckmann.github.com/gm/docs.html#threshold) - - [thumb](http://aheckmann.github.com/gm/docs.html#thumb) - - [tile](http://aheckmann.github.com/gm/docs.html#tile) - - [transform](http://aheckmann.github.com/gm/docs.html#transform) - - [transparent](http://aheckmann.github.com/gm/docs.html#transparent) - - [treeDepth](http://aheckmann.github.com/gm/docs.html#treeDepth) - - [trim](http://aheckmann.github.com/gm/docs.html#trim) - - [type](http://aheckmann.github.com/gm/docs.html#type) - - [update](http://aheckmann.github.com/gm/docs.html#update) - - [units](http://aheckmann.github.com/gm/docs.html#units) - - [unsharp](http://aheckmann.github.com/gm/docs.html#unsharp) - - [usePixmap](http://aheckmann.github.com/gm/docs.html#usePixmap) - - [view](http://aheckmann.github.com/gm/docs.html#view) - - [virtualPixel](http://aheckmann.github.com/gm/docs.html#virtualPixel) - - [visual](http://aheckmann.github.com/gm/docs.html#visual) - - [watermark](http://aheckmann.github.com/gm/docs.html#watermark) - - [wave](http://aheckmann.github.com/gm/docs.html#wave) - - [whitePoint](http://aheckmann.github.com/gm/docs.html#whitePoint) - - [whiteThreshold](http://aheckmann.github.com/gm/docs.html#whiteThreshold) - - [window](http://aheckmann.github.com/gm/docs.html#window) - - [windowGroup](http://aheckmann.github.com/gm/docs.html#windowGroup) + - [adjoin](http://aheckmann.github.io/gm/docs.html#adjoin) + - [affine](http://aheckmann.github.io/gm/docs.html#affine) + - [antialias](http://aheckmann.github.io/gm/docs.html#antialias) + - [append](http://aheckmann.github.io/gm/docs.html#append) + - [authenticate](http://aheckmann.github.io/gm/docs.html#authenticate) + - [autoOrient](http://aheckmann.github.io/gm/docs.html#autoOrient) + - [average](http://aheckmann.github.io/gm/docs.html#average) + - [backdrop](http://aheckmann.github.io/gm/docs.html#backdrop) + - [bitdepth](http://aheckmann.github.io/gm/docs.html#bitdepth) + - [blackThreshold](http://aheckmann.github.io/gm/docs.html#blackThreshold) + - [bluePrimary](http://aheckmann.github.io/gm/docs.html#bluePrimary) + - [blur](http://aheckmann.github.io/gm/docs.html#blur) + - [border](http://aheckmann.github.io/gm/docs.html#border) + - [borderColor](http://aheckmann.github.io/gm/docs.html#borderColor) + - [box](http://aheckmann.github.io/gm/docs.html#box) + - [channel](http://aheckmann.github.io/gm/docs.html#channel) + - [charcoal](http://aheckmann.github.io/gm/docs.html#charcoal) + - [chop](http://aheckmann.github.io/gm/docs.html#chop) + - [clip](http://aheckmann.github.io/gm/docs.html#clip) + - [coalesce](http://aheckmann.github.io/gm/docs.html#coalesce) + - [colors](http://aheckmann.github.io/gm/docs.html#colors) + - [colorize](http://aheckmann.github.io/gm/docs.html#colorize) + - [colorMap](http://aheckmann.github.io/gm/docs.html#colorMap) + - [colorspace](http://aheckmann.github.io/gm/docs.html#colorspace) + - [comment](http://aheckmann.github.io/gm/docs.html#comment) + - [compose](http://aheckmann.github.io/gm/docs.html#compose) + - [compress](http://aheckmann.github.io/gm/docs.html#compress) + - [contrast](http://aheckmann.github.io/gm/docs.html#contrast) + - [convolve](http://aheckmann.github.io/gm/docs.html#convolve) + - [createDirectories](http://aheckmann.github.io/gm/docs.html#createDirectories) + - [crop](http://aheckmann.github.io/gm/docs.html#crop) + - [cycle](http://aheckmann.github.io/gm/docs.html#cycle) + - [deconstruct](http://aheckmann.github.io/gm/docs.html#deconstruct) + - [delay](http://aheckmann.github.io/gm/docs.html#delay) + - [define](http://aheckmann.github.io/gm/docs.html#define) + - [density](http://aheckmann.github.io/gm/docs.html#density) + - [despeckle](http://aheckmann.github.io/gm/docs.html#despeckle) + - [dither](http://aheckmann.github.io/gm/docs.html#dither) + - [displace](http://aheckmann.github.io/gm/docs.html#dither) + - [display](http://aheckmann.github.io/gm/docs.html#display) + - [dispose](http://aheckmann.github.io/gm/docs.html#dispose) + - [dissolve](http://aheckmann.github.io/gm/docs.html#dissolve) + - [edge](http://aheckmann.github.io/gm/docs.html#edge) + - [emboss](http://aheckmann.github.io/gm/docs.html#emboss) + - [encoding](http://aheckmann.github.io/gm/docs.html#encoding) + - [enhance](http://aheckmann.github.io/gm/docs.html#enhance) + - [endian](http://aheckmann.github.io/gm/docs.html#endian) + - [equalize](http://aheckmann.github.io/gm/docs.html#equalize) + - [extent](http://aheckmann.github.io/gm/docs.html#extent) + - [file](http://aheckmann.github.io/gm/docs.html#file) + - [filter](http://aheckmann.github.io/gm/docs.html#filter) + - [flatten](http://aheckmann.github.io/gm/docs.html#flatten) + - [flip](http://aheckmann.github.io/gm/docs.html#flip) + - [flop](http://aheckmann.github.io/gm/docs.html#flop) + - [foreground](http://aheckmann.github.io/gm/docs.html#foreground) + - [frame](http://aheckmann.github.io/gm/docs.html#frame) + - [fuzz](http://aheckmann.github.io/gm/docs.html#fuzz) + - [gamma](http://aheckmann.github.io/gm/docs.html#gamma) + - [gaussian](http://aheckmann.github.io/gm/docs.html#gaussian) + - [geometry](http://aheckmann.github.io/gm/docs.html#geometry) + - [gravity](http://aheckmann.github.io/gm/docs.html#gravity) + - [greenPrimary](http://aheckmann.github.io/gm/docs.html#greenPrimary) + - [highlightColor](http://aheckmann.github.io/gm/docs.html#highlightColor) + - [highlightStyle](http://aheckmann.github.io/gm/docs.html#highlightStyle) + - [iconGeometry](http://aheckmann.github.io/gm/docs.html#iconGeometry) + - [implode](http://aheckmann.github.io/gm/docs.html#implode) + - [intent](http://aheckmann.github.io/gm/docs.html#intent) + - [interlace](http://aheckmann.github.io/gm/docs.html#interlace) + - [label](http://aheckmann.github.io/gm/docs.html#label) + - [lat](http://aheckmann.github.io/gm/docs.html#lat) + - [level](http://aheckmann.github.io/gm/docs.html#level) + - [list](http://aheckmann.github.io/gm/docs.html#list) + - [limit](http://aheckmann.github.io/gm/docs.html#limit) + - [log](http://aheckmann.github.io/gm/docs.html#log) + - [loop](http://aheckmann.github.io/gm/docs.html#loop) + - [lower](http://aheckmann.github.io/gm/docs.html#lower) + - [magnify](http://aheckmann.github.io/gm/docs.html#magnify) + - [map](http://aheckmann.github.io/gm/docs.html#map) + - [matte](http://aheckmann.github.io/gm/docs.html#matte) + - [matteColor](http://aheckmann.github.io/gm/docs.html#matteColor) + - [mask](http://aheckmann.github.io/gm/docs.html#mask) + - [maximumError](http://aheckmann.github.io/gm/docs.html#maximumError) + - [median](http://aheckmann.github.io/gm/docs.html#median) + - [minify](http://aheckmann.github.io/gm/docs.html#minify) + - [mode](http://aheckmann.github.io/gm/docs.html#mode) + - [modulate](http://aheckmann.github.io/gm/docs.html#modulate) + - [monitor](http://aheckmann.github.io/gm/docs.html#monitor) + - [monochrome](http://aheckmann.github.io/gm/docs.html#monochrome) + - [morph](http://aheckmann.github.io/gm/docs.html#morph) + - [mosaic](http://aheckmann.github.io/gm/docs.html#mosaic) + - [motionBlur](http://aheckmann.github.io/gm/docs.html#motionBlur) + - [name](http://aheckmann.github.io/gm/docs.html#name) + - [negative](http://aheckmann.github.io/gm/docs.html#negative) + - [noise](http://aheckmann.github.io/gm/docs.html#noise) + - [noop](http://aheckmann.github.io/gm/docs.html#noop) + - [normalize](http://aheckmann.github.io/gm/docs.html#normalize) + - [noProfile](http://aheckmann.github.io/gm/docs.html#profile) + - [opaque](http://aheckmann.github.io/gm/docs.html#opaque) + - [operator](http://aheckmann.github.io/gm/docs.html#operator) + - [orderedDither](http://aheckmann.github.io/gm/docs.html#orderedDither) + - [outputDirectory](http://aheckmann.github.io/gm/docs.html#outputDirectory) + - [paint](http://aheckmann.github.io/gm/docs.html#paint) + - [page](http://aheckmann.github.io/gm/docs.html#page) + - [pause](http://aheckmann.github.io/gm/docs.html#pause) + - [pen](http://aheckmann.github.io/gm/docs.html#pen) + - [ping](http://aheckmann.github.io/gm/docs.html#ping) + - [pointSize](http://aheckmann.github.io/gm/docs.html#pointSize) + - [preview](http://aheckmann.github.io/gm/docs.html#preview) + - [process](http://aheckmann.github.io/gm/docs.html#process) + - [profile](http://aheckmann.github.io/gm/docs.html#profile) + - [progress](http://aheckmann.github.io/gm/docs.html#progress) + - [quality](http://aheckmann.github.io/gm/docs.html#quality) + - [raise](http://aheckmann.github.io/gm/docs.html#raise) + - [rawSize](http://aheckmann.github.io/gm/docs.html#rawSize) + - [randomThreshold](http://aheckmann.github.io/gm/docs.html#randomThreshold) + - [recolor](http://aheckmann.github.io/gm/docs.html#recolor) + - [redPrimary](http://aheckmann.github.io/gm/docs.html#redPrimary) + - [region](http://aheckmann.github.io/gm/docs.html#region) + - [remote](http://aheckmann.github.io/gm/docs.html#remote) + - [render](http://aheckmann.github.io/gm/docs.html#render) + - [repage](http://aheckmann.github.io/gm/docs.html#repage) + - [resample](http://aheckmann.github.io/gm/docs.html#resample) + - [resize](http://aheckmann.github.io/gm/docs.html#resize) + - [roll](http://aheckmann.github.io/gm/docs.html#roll) + - [rotate](http://aheckmann.github.io/gm/docs.html#rotate) + - [sample](http://aheckmann.github.io/gm/docs.html#sample) + - [samplingFactor](http://aheckmann.github.io/gm/docs.html#samplingFactor) + - [scale](http://aheckmann.github.io/gm/docs.html#scale) + - [scene](http://aheckmann.github.io/gm/docs.html#scene) + - [scenes](http://aheckmann.github.io/gm/docs.html#scenes) + - [screen](http://aheckmann.github.io/gm/docs.html#screen) + - [segment](http://aheckmann.github.io/gm/docs.html#segment) + - [sepia](http://aheckmann.github.io/gm/docs.html#sepia) + - [set](http://aheckmann.github.io/gm/docs.html#set) + - [setFormat](http://aheckmann.github.io/gm/docs.html#setformat) + - [shade](http://aheckmann.github.io/gm/docs.html#shade) + - [shadow](http://aheckmann.github.io/gm/docs.html#shadow) + - [sharedMemory](http://aheckmann.github.io/gm/docs.html#sharedMemory) + - [sharpen](http://aheckmann.github.io/gm/docs.html#sharpen) + - [shave](http://aheckmann.github.io/gm/docs.html#shave) + - [shear](http://aheckmann.github.io/gm/docs.html#shear) + - [silent](http://aheckmann.github.io/gm/docs.html#silent) + - [solarize](http://aheckmann.github.io/gm/docs.html#solarize) + - [snaps](http://aheckmann.github.io/gm/docs.html#snaps) + - [stegano](http://aheckmann.github.io/gm/docs.html#stegano) + - [stereo](http://aheckmann.github.io/gm/docs.html#stereo) + - [strip](http://aheckmann.github.io/gm/docs.html#strip) _imagemagick only_ + - [spread](http://aheckmann.github.io/gm/docs.html#spread) + - [swirl](http://aheckmann.github.io/gm/docs.html#swirl) + - [textFont](http://aheckmann.github.io/gm/docs.html#textFont) + - [texture](http://aheckmann.github.io/gm/docs.html#texture) + - [threshold](http://aheckmann.github.io/gm/docs.html#threshold) + - [thumb](http://aheckmann.github.io/gm/docs.html#thumb) + - [tile](http://aheckmann.github.io/gm/docs.html#tile) + - [transform](http://aheckmann.github.io/gm/docs.html#transform) + - [transparent](http://aheckmann.github.io/gm/docs.html#transparent) + - [treeDepth](http://aheckmann.github.io/gm/docs.html#treeDepth) + - [trim](http://aheckmann.github.io/gm/docs.html#trim) + - [type](http://aheckmann.github.io/gm/docs.html#type) + - [update](http://aheckmann.github.io/gm/docs.html#update) + - [units](http://aheckmann.github.io/gm/docs.html#units) + - [unsharp](http://aheckmann.github.io/gm/docs.html#unsharp) + - [usePixmap](http://aheckmann.github.io/gm/docs.html#usePixmap) + - [view](http://aheckmann.github.io/gm/docs.html#view) + - [virtualPixel](http://aheckmann.github.io/gm/docs.html#virtualPixel) + - [visual](http://aheckmann.github.io/gm/docs.html#visual) + - [watermark](http://aheckmann.github.io/gm/docs.html#watermark) + - [wave](http://aheckmann.github.io/gm/docs.html#wave) + - [whitePoint](http://aheckmann.github.io/gm/docs.html#whitePoint) + - [whiteThreshold](http://aheckmann.github.io/gm/docs.html#whiteThreshold) + - [window](http://aheckmann.github.io/gm/docs.html#window) + - [windowGroup](http://aheckmann.github.io/gm/docs.html#windowGroup) - drawing primitives - - [draw](http://aheckmann.github.com/gm/docs.html#draw) - - [drawArc](http://aheckmann.github.com/gm/docs.html#drawArc) - - [drawBezier](http://aheckmann.github.com/gm/docs.html#drawBezier) - - [drawCircle](http://aheckmann.github.com/gm/docs.html#drawCircle) - - [drawEllipse](http://aheckmann.github.com/gm/docs.html#drawEllipse) - - [drawLine](http://aheckmann.github.com/gm/docs.html#drawLine) - - [drawPoint](http://aheckmann.github.com/gm/docs.html#drawPoint) - - [drawPolygon](http://aheckmann.github.com/gm/docs.html#drawPolygon) - - [drawPolyline](http://aheckmann.github.com/gm/docs.html#drawPolyline) - - [drawRectangle](http://aheckmann.github.com/gm/docs.html#drawRectangle) - - [drawText](http://aheckmann.github.com/gm/docs.html#drawText) - - [fill](http://aheckmann.github.com/gm/docs.html#fill) - - [font](http://aheckmann.github.com/gm/docs.html#font) - - [fontSize](http://aheckmann.github.com/gm/docs.html#fontSize) - - [stroke](http://aheckmann.github.com/gm/docs.html#stroke) - - [strokeWidth](http://aheckmann.github.com/gm/docs.html#strokeWidth) - - [setDraw](http://aheckmann.github.com/gm/docs.html#setDraw) + - [draw](http://aheckmann.github.io/gm/docs.html#draw) + - [drawArc](http://aheckmann.github.io/gm/docs.html#drawArc) + - [drawBezier](http://aheckmann.github.io/gm/docs.html#drawBezier) + - [drawCircle](http://aheckmann.github.io/gm/docs.html#drawCircle) + - [drawEllipse](http://aheckmann.github.io/gm/docs.html#drawEllipse) + - [drawLine](http://aheckmann.github.io/gm/docs.html#drawLine) + - [drawPoint](http://aheckmann.github.io/gm/docs.html#drawPoint) + - [drawPolygon](http://aheckmann.github.io/gm/docs.html#drawPolygon) + - [drawPolyline](http://aheckmann.github.io/gm/docs.html#drawPolyline) + - [drawRectangle](http://aheckmann.github.io/gm/docs.html#drawRectangle) + - [drawText](http://aheckmann.github.io/gm/docs.html#drawText) + - [fill](http://aheckmann.github.io/gm/docs.html#fill) + - [font](http://aheckmann.github.io/gm/docs.html#font) + - [fontSize](http://aheckmann.github.io/gm/docs.html#fontSize) + - [stroke](http://aheckmann.github.io/gm/docs.html#stroke) + - [strokeWidth](http://aheckmann.github.io/gm/docs.html#strokeWidth) + - [setDraw](http://aheckmann.github.io/gm/docs.html#setDraw) - image output - **write** - writes the processed image data to the specified filename - **stream** - provides a `ReadableStream` with the processed image data - **toBuffer** - returns the image as a `Buffer` instead of a stream -##compare +## compare Graphicsmagicks `compare` command is exposed through `gm.compare()`. This allows us to determine if two images can be considered "equal". @@ -568,7 +588,7 @@ gm.compare('/path/to/image1.jpg', '/path/to/another.png', options, function (err }) ``` -##composite +## composite GraphicsMagick supports compositing one image on top of another. This is exposed through `gm.composite()`. Its first argument is an image path with the changes to the base image, and an optional mask image. @@ -585,7 +605,7 @@ gm('/path/to/image.jpg') }); ``` -##montage +## montage GraphicsMagick supports montage for combining images side by side. This is exposed through `gm.montage()`. Its only argument is an image path with the changes to the base image. @@ -611,6 +631,15 @@ http://github.com/quiiver/magickal-node ## Plugins [https://github.com/aheckmann/gm/wiki](https://github.com/aheckmann/gm/wiki) +## Tests +`npm test` + +To run a single test: + +``` +npm test -- alpha.js +``` + ## License (The MIT License) diff --git a/index.js b/index.js index 6e622d8a..30d34971 100644 --- a/index.js +++ b/index.js @@ -74,6 +74,11 @@ function gm (source, height, color) { var inputFromStdin = this.sourceStream || this.sourceBuffer; var ret = inputFromStdin ? '-' : this.source; + const fileNameProvied = typeof height === 'string'; + if (inputFromStdin && fileNameProvied && /\.ico$/i.test(this.source)) { + ret = `ico:-`; + } + if (ret && this.sourceFrames) ret += this.sourceFrames; src.length = 0; @@ -126,7 +131,4 @@ require("./lib/montage")(gm.prototype); module.exports = exports = gm; module.exports.utils = require('./lib/utils'); module.exports.compare = require('./lib/compare')(); -module.exports.version = JSON.parse( - require('fs').readFileSync(__dirname + '/package.json', 'utf8') -).version; - +module.exports.version = require('./package.json').version; diff --git a/lib/args.js b/lib/args.js index 5bffdd2f..35089f77 100644 --- a/lib/args.js +++ b/lib/args.js @@ -589,8 +589,25 @@ module.exports = function (proto) { } // http://www.graphicsmagick.org/GraphicsMagick.html#details-thumbnail - proto.thumbnail = function thumbnail (width, height) { - return this.out("-thumbnail", width + "x" + height); + proto.thumbnail = function thumbnail (w, h, options) { + options = options || ""; + var geometry, + wIsValid = Boolean(w || w === 0), + hIsValid = Boolean(h || h === 0); + + if (wIsValid && hIsValid) { + geometry = w + "x" + h + options + } else if (wIsValid) { + // GraphicsMagick requires x, ImageMagick requires + geometry = (this._options.imageMagick) ? w + options : w + + 'x' + options; + } else if (hIsValid) { + geometry = 'x' + h + options + } else { + return this + } + + return this.out("-thumbnail", geometry); } // http://www.graphicsmagick.org/GraphicsMagick.html#details-tile diff --git a/lib/command.js b/lib/command.js index 9811f739..46930cdc 100644 --- a/lib/command.js +++ b/lib/command.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var spawn = require('child_process').spawn; +var spawn = require('cross-spawn'); var utils = require('./utils'); var debug = require('debug')('gm'); var series = require('array-series'); @@ -35,7 +35,7 @@ module.exports = function (proto) { return this; } } - + function streamToUnemptyBuffer(stream, callback) { var done = false var buffers = [] @@ -45,19 +45,18 @@ module.exports = function (proto) { }) stream.on('end', function () { - var result, err; if (done) return done = true - result = Buffer.concat(buffers) + let result = Buffer.concat(buffers) buffers = null - if (result.length==0) - { - err = new Error("Stream yields empty buffer"); - callback(err, null); + + if (result.length === 0) { + const err = new Error("Stream yields empty buffer"); + callback(err, null); } else { - callback(null, result); + callback(null, result); } }) @@ -196,28 +195,47 @@ module.exports = function (proto) { * @param {Array} args * @param {ReadableStream} stream * @param {Boolean} shouldBuffer - * @param {Function} callback, signature (err, stdout, stderr) -> * + * @param {Function} callback, signature (err, stdout, stderr) -> * * @return {Object} gm * @TODO refactor this mess */ proto._spawn = function _spawn (args, bufferOutput, callback) { var appPath = this._options.appPath || ''; - var bin = this._options.imageMagick - ? appPath + args.shift() - : appPath + 'gm' + var bin + + // Resolve executable + switch (this._options.imageMagick) { + // legacy behavior + case true: + bin = args.shift(); + break; + + // ImgeMagick >= 7 + case '7+': + bin = 'magick' + break; + + // GraphicsMagick + default: + bin = 'gm'; + break; + } + + // Prepend app path + bin = appPath + bin var cmd = bin + ' ' + args.map(utils.escape).join(' ') , self = this , proc, err , timeout = parseInt(this._options.timeout) + , disposers = this._options.disposers , timeoutId; debug(cmd); //imageMagick does not support minify (https://github.com/aheckmann/gm/issues/385) if(args.indexOf("-minify") > -1 && this._options.imageMagick){ - err = new Error("imageMagick does not support minify, use -scale or -sample. Alternatively, use graphicsMagick"); - return cb(err); + return cb(new Error("imageMagick does not support minify, use -scale or -sample. Alternatively, use graphicsMagick")); } try { proc = spawn(bin, args); @@ -226,25 +244,35 @@ module.exports = function (proto) { } proc.stdin.once('error', cb); + proc.on('error', function(err){ + if (err.code === 'ENOENT') { + cb(new Error('Could not execute GraphicsMagick/ImageMagick: '+cmd+" this most likely means the gm/convert binaries can't be found")); + } else { + cb(err); + } + }); + if (timeout) { timeoutId = setTimeout(function(){ - err = new Error('gm() resulted in a timeout.'); - cb(err); - if (proc.connected) { - proc.stdin.pause(); - proc.kill(); - } + dispose('gm() resulted in a timeout.'); }, timeout); } + if (disposers) { + disposers.forEach(function(disposer) { + disposer.events.forEach(function(event) { + disposer.emitter.on(event, dispose); + }); + }); + } + if (self.sourceBuffer) { proc.stdin.write(this.sourceBuffer); proc.stdin.end(); } else if (self.sourceStream) { if (!self.sourceStream.readable) { - err = new Error("gm().stream() or gm().write() with a non-readable stream."); - return cb(err); + return cb(new Error("gm().stream() or gm().write() with a non-readable stream.")); } self.sourceStream.pipe(proc.stdin); @@ -285,6 +313,7 @@ module.exports = function (proto) { }); proc.on('close', onExit = function (code, signal) { + let err; if (code !== 0 || signal !== null) { err = new Error('Command failed: ' + stderr); err.code = code; @@ -293,14 +322,6 @@ module.exports = function (proto) { cb(err, stdout, stderr, cmd); stdout = stderr = onOut = onErr = onExit = null; }); - - proc.on('error', function(err){ - if (err.code === 'ENOENT') { - cb(new Error('Could not execute GraphicsMagick/ImageMagick: '+cmd+" this most likely means the gm/convert binaries can't be found")); - } else { - cb(err); - } - }); } else { cb(null, proc.stdout, proc.stderr, cmd); } @@ -311,12 +332,22 @@ module.exports = function (proto) { if (cb.called) return; if (timeoutId) clearTimeout(timeoutId); cb.called = 1; - if (args[0] !== 'identify' && bin !== 'identify') { - self._in = []; - self._out = []; - } + if (args[0] !== 'identify' && bin !== 'identify') { + self._in = []; + self._out = []; + } callback.call(self, err, stdout, stderr, cmd); } + + function dispose (msg) { + const message = msg ? msg : 'gm() was disposed'; + const err = new Error(message); + cb(err); + if (proc.exitCode === null) { + proc.stdin.pause(); + proc.kill(); + } + } } /** @@ -408,4 +439,25 @@ module.exports = function (proto) { return rgx.test(this.source); } + + /** + * add disposer (like 'close' of http.IncomingMessage) in order to dispose gm() with any event + * + * @param {EventEmitter} emitter + * @param {Array} events + * @return {Object} gm + * @example + * command.addDisposer(req, ['close', 'end', 'finish']); + */ + + proto.addDisposer = function addDisposer (emitter, events) { + if (!this._options.disposers) { + this._options.disposers = []; + } + this._options.disposers.push({ + emitter: emitter, + events: events + }); + return this; + }; } diff --git a/lib/compare.js b/lib/compare.js index 07a56af2..7ba33976 100644 --- a/lib/compare.js +++ b/lib/compare.js @@ -1,6 +1,7 @@ // compare -var exec = require('child_process').exec; +var spawn = require('cross-spawn'); +var debug = require('debug')('gm'); var utils = require('./utils'); /** @@ -20,13 +21,31 @@ var utils = require('./utils'); module.exports = exports = function (proto) { function compare(orig, compareTo, options, cb) { - orig = utils.escape(orig); - compareTo = utils.escape(compareTo); var isImageMagick = this._options && this._options.imageMagick; - // compare binary for IM is `compare`, for GM it's `gm compare` - var bin = isImageMagick ? '' : 'gm '; - var execCmd = bin + 'compare -metric mse ' + orig + ' ' + compareTo; + var appPath = this._options && this._options.appPath || ''; + var args = ['-metric', 'mse', orig, compareTo]; + + // Resove executable + let bin; + + switch (isImageMagick) { + case true: + bin = 'compare'; + break; + case '7+': + bin = 'magick' + args.unshift('compare'); + break; + default: + bin = 'gm' + args.unshift('compare'); + break + } + + // Prepend app path + bin = appPath + bin + var tolerance = 0.4; // outputting the diff image if (typeof options === 'object') { @@ -40,27 +59,32 @@ module.exports = exports = function (proto) { throw new TypeError('The path for the diff output is invalid'); } // graphicsmagick defaults to red - var highlightColorOption = options.highlightColor - ? ' -highlight-color ' + options.highlightColor + ' ' - : ' '; - var highlightStyleOption = options.highlightStyle - ? ' -highlight-style ' + options.highlightStyle + ' ' - : ' '; - var diffFilename = utils.escape(options.file); + if (options.highlightColor) { + args.push('-highlight-color'); + args.push(options.highlightColor); + } + if (options.highlightStyle) { + args.push('-highlight-style') + args.push(options.highlightStyle) + } // For IM, filename is the last argument. For GM it's `-file ` - var diffOpt = isImageMagick ? diffFilename : ('-file ' + diffFilename); - execCmd += highlightColorOption + highlightStyleOption + ' ' + diffOpt; + if (!isImageMagick) { + args.push('-file'); + } + args.push(options.file); } - + if (typeof options.tolerance != 'undefined') { if (typeof options.tolerance !== 'number') { throw new TypeError('The tolerance value should be a number'); } tolerance = options.tolerance; - } + } } else { // For ImageMagick diff file is required but we don't care about it, so null it out - isImageMagick && (execCmd += ' null:'); + if (isImageMagick) { + args.push('null:'); + } if (typeof options == 'function') { cb = options; // tolerance value not provided, flip the cb place @@ -69,31 +93,40 @@ module.exports = exports = function (proto) { } } - exec(execCmd, function (err, stdout, stderr) { + var cmd = bin + ' ' + args.map(utils.escape).join(' ') + debug(cmd); + + var proc = spawn(bin, args); + var stdout = ''; + var stderr = ''; + proc.stdout.on('data',function(data) { stdout+=data }); + proc.stderr.on('data',function(data) { stderr+=data }); + proc.on('close', function (code) { // ImageMagick returns err code 2 if err, 0 if similar, 1 if dissimilar if (isImageMagick) { - if (!err) { + if (code === 0) { return cb(null, 0 <= tolerance, 0, stdout); } - if (err.code === 1) { - err = null; + else if (code === 1) { stdout = stderr; + } else { + return cb(stderr); + } + } else { + if(code !== 0) { + return cb(stderr); } - } - if (err) { - return cb(err); } // Since ImageMagick similar gives err code 0 and no stdout, there's really no matching // Otherwise, output format for IM is `12.00 (0.123)` and for GM it's `Total: 0.123` var regex = isImageMagick ? /\((\d+\.?[\d\-\+e]*)\)/m : /Total: (\d+\.?\d*)/m; var match = regex.exec(stdout); if (!match) { - err = new Error('Unable to parse output.\nGot ' + stdout); - return cb(err); + return cb(new Error('Unable to parse output.\nGot ' + stdout)); } var equality = parseFloat(match[1]); - cb(null, equality <= tolerance, equality, stdout, utils.unescape(orig), utils.unescape(compareTo)); + cb(null, equality <= tolerance, equality, stdout, orig, compareTo); }); } diff --git a/lib/composite.js b/lib/composite.js index 069a3b94..ca90440f 100644 --- a/lib/composite.js +++ b/lib/composite.js @@ -1,7 +1,5 @@ // composite -var utils = require('./utils'); - /** * Composite images together using the `composite` command in graphicsmagick. * diff --git a/lib/convenience/autoOrient.js b/lib/convenience/autoOrient.js index e16c2a92..78ff2d18 100644 --- a/lib/convenience/autoOrient.js +++ b/lib/convenience/autoOrient.js @@ -25,7 +25,6 @@ module.exports = function (proto) { // nativeAutoOrient option enables this if you know you have >= 1.3.18 if (this._options.nativeAutoOrient || this._options.imageMagick) { this.out('-auto-orient'); - this.strip(); return this; } @@ -46,8 +45,6 @@ module.exports = function (proto) { this._out.unshift.apply(this._out, transforms.concat('-page', '+0+0')); } - this.strip(); - callback(); }); }); diff --git a/lib/getters.js b/lib/getters.js index 88317c5b..14bbcf05 100755 --- a/lib/getters.js +++ b/lib/getters.js @@ -221,14 +221,27 @@ module.exports = function (gm) { } else if (indent > level) { // dropping into a nested object out.indent[level] = o; - // wierd format, key/val pair with nested children. discard the val + // weird format, key/val pair with nested children. discard the val o = o[lastkey] = {}; } level = indent; if (val) { - o[key] = val; + // if previous key was exist and we got the same key + // cast it to an array. + if(o.hasOwnProperty(key)){ + // cast it to an array and dont forget the previous value + if(!Array.isArray(o[key])){ + var tmp = o[key]; + o[key] = [tmp]; + } + + // set value + o[key].push(val); + } else { + o[key] = val; + } if (key in helper) { helper[key](o, val); @@ -330,3 +343,4 @@ module.exports = function (gm) { } }; } + diff --git a/lib/montage.js b/lib/montage.js index 8e9ccc10..3120be84 100644 --- a/lib/montage.js +++ b/lib/montage.js @@ -1,7 +1,5 @@ // montage -var utils = require('./utils'); - /** * Montage images next to each other using the `montage` command in graphicsmagick. * diff --git a/package.json b/package.json index 50dd723f..73c866a6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gm", "description": "GraphicsMagick and ImageMagick for node.js", - "version": "1.19.0", + "version": "1.25.0", "author": "Aaron Heckmann ", "keywords": [ "graphics", @@ -15,7 +15,7 @@ "compare" ], "engines": { - "node": ">= 0.10.0" + "node": ">=14" }, "bugs": { "url": "http://github.com/aheckmann/gm/issues" @@ -28,7 +28,10 @@ ], "main": "./index", "scripts": { - "test": "make test-unit; make test;" + "security": "npm audit", + "test": "npm run security && npm run test-integration", + "test-integration": "node test/ --integration", + "test-unit": "node test/" }, "repository": { "type": "git", @@ -36,12 +39,12 @@ }, "license": "MIT", "devDependencies": { - "gleak": "~0.5.0", "async": "~0.9.0" }, "dependencies": { - "debug": "~2.2.0", + "array-parallel": "~0.1.3", "array-series": "~0.1.5", - "array-parallel": "~0.1.3" + "cross-spawn": "^4.0.0", + "debug": "^3.1.0" } } diff --git a/test/109.js b/test/109.js index 55992c28..41332380 100644 --- a/test/109.js +++ b/test/109.js @@ -1,17 +1,14 @@ -var assert = require('assert') -var fs = require('fs') +const fs = require('fs'); +const path = require('path'); -module.exports = function (_, dir, finish, gm) { - if (!gm.integration) - return finish(); +module.exports = function (_, dir, finish, gm, imageMagick) { + if (!gm.integration) return finish(); - var original = dir + '/original.jpg'; - var result = dir + '/fromBuffer.png'; + const original = path.join(dir, 'original.jpg'); + const buf = fs.readFileSync(original); + const m = gm(buf, 'original.jpg').options({ imageMagick }); - var buf = fs.readFileSync(original); - var m = gm(buf, 'original.jpg'); - - m.identify(function (err, x) { + m.identify(function (err, _) { finish(err); }); diff --git a/test/118.js b/test/118.js index fad472eb..17c98d5f 100644 --- a/test/118.js +++ b/test/118.js @@ -1,21 +1,22 @@ /* - * If only the width is specified for a resize operation, + * If only the width is specified for a resize operation, * GraphicsMagick requires the format * -resize 10x * while ImageMagick requires the format - * -resize 10 + * -resize 10 * */ -var assert = require('assert') +const assert = require('assert') +const path = require('path'); -module.exports = function (_, dir, finish, gm) { - if (!gm.integration) return finish(); - - var src = dir + '/originalSideways.jpg'; - var dst = dir + '/originalSideways10x.jpg'; +module.exports = function (_, dir, finish, gm, imageMagick) { + if (!gm.integration) return finish(); - gm(src).resize(10).write(dst, function(err) { - gm(dst).size(function(err, size) { + var src = path.join(dir, 'originalSideways.jpg'); + var dst = path.join(dir, 'originalSideways10x.jpg'); + + gm(src).options({ imageMagick }).resize(10).write(dst, function(err) { + gm(dst).options({ imageMagick }).size(function(err, size) { if (err) return finish(err); assert.equal(10, size.width); finish(); diff --git a/test/393.js b/test/393.js index b339b0a1..dc0cdb45 100644 --- a/test/393.js +++ b/test/393.js @@ -1,16 +1,13 @@ -'use strict'; +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var imagePath = path.join(__dirname, './fixtures/nyancat.gif'); + var imagePath = path.join(__dirname, 'fixtures', 'nyancat.gif'); var inputStream = fs.createReadStream(imagePath); - gm(inputStream) - .identify({ bufferStream: true }, function(err, value) { + gm(inputStream).options({ imageMagick }).identify({ bufferStream: true }, function(err, value) { if (err) return finish(err); var size = value.size; assert.equal(400, size.width); diff --git a/test/417.js b/test/417.js index d146aaa9..2e88952c 100644 --- a/test/417.js +++ b/test/417.js @@ -1,30 +1,29 @@ -var assert = require('assert') -var fs = require('fs'); -var path = require('path'); +const assert = require('assert') +const fs = require('fs'); +const path = require('path'); -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - gm(dir + '/original.jpg') - .thumb(150, 40, dir + '/thumb.png', function thumb (err) { - gm(dir + '/thumb.png') - .size(function (err, size) { - if (err) return finish(err); + const originalPathName = path.join(dir, 'original.jpg'); + const thumbPathName = path.join(dir, 'thumb.png'); - assert.equal(142, size.width); - assert.equal(40, size.height); + gm(originalPathName).options({ imageMagick }).thumb(150, 40, thumbPathName, function thumb (err) { + gm(thumbPathName).options({ imageMagick }).size(function (err, size) { + if (err) return finish(err); - gm(dir + '/original.jpg') - .thumbExact(150, 40, dir + '/thumb.png', function thumb (err) { - gm(dir + '/thumb.png') - .size(function (err, size) { - assert.equal(150, size.width); - assert.equal(40, size.height); - finish(err); - }); + assert.equal(142, size.width); + assert.equal(40, size.height); + + gm(originalPathName).options({ imageMagick }).thumbExact(150, 40, thumbPathName, function thumb (err) { + gm(thumbPathName).options({ imageMagick }).size(function (err, size) { + assert.equal(150, size.width); + assert.equal(40, size.height); + finish(err); }); }); + }); }); } diff --git a/test/422.js b/test/422.js index 1f0d29ef..d980439e 100644 --- a/test/422.js +++ b/test/422.js @@ -1,39 +1,56 @@ -var assert = require('assert'); -var fs = require('fs'); +const fs = require('fs'); +const path = require('path'); -module.exports = function (gm, dir, finish, GM) { +module.exports = function (gm, dir, finish, GM, imageMagick) { // Same image - GM.compare(dir + '/original.jpg', dir + '/original.png', function(err, same) { + const originalPathName = path.join(dir, 'original.jpg'); + + gm.compare(originalPathName, originalPathName, function(err, same, diff) { if (err) return finish(err); - if (!same) return finish(new Error('Compare should be the same!')); + if (!same) { + const msg = `Compare should be the same! "${same}" "${diff}"`; + return finish(new Error(msg)); + } // Compare almost similar images for which ImageMagick - // returns a exponent-style floating point number - gm.compare(__dirname + '/fixtures/compare_1.png', __dirname + '/fixtures/compare_2.png', function(err, same, diff) { + // returns an exponent-style floating point number + const compare1PathName = path.join(__dirname, 'fixtures', 'compare_1.png'); + const compare2PathName = path.join(__dirname, 'fixtures', 'compare_2.png'); + + gm.compare(compare1PathName, compare2PathName, function(err, same, diff) { if (err) return finish(err); + if (!same) { + const msg = `Compare should be the same! "${same}" "${diff}"`; + return finish(new Error(msg)); + } + + const noisePathName = path.join(dir, 'noise3.png'); // Create a new noisy image - gm.noise(0.3).write(dir + '/noise3.png', function (err) { + gm.noise(0.3).write(noisePathName, function (err) { if (err) return finish(err); - if (!same) return finish(new Error('Compare should be the same!')); var options = { highlightColor: '#fff', - highlightStyle: 'XOR', - file: dir + '/diff.png', + file: path.join(dir, 'diff.png'), tolerance: 0.001 }; + const originalPathName = path.join(dir, 'original.jpg'); + // Compare these images and write to a file. - GM.compare(dir + '/original.jpg', dir + '/noise3.png', options, function(err) { + gm.compare(originalPathName, noisePathName, options, function(err) { if (err) return finish(err); - fs.exists(options.file, function(exists) { - if (exists) finish(); - else finish(new Error('Diff file does not exist.')); + fs.access(options.file, fs.constants.F_OK, function(err) { + if (err) { + finish(new Error('Diff file does not exist.')); + } else { + fs.unlink(options.file, finish); + } }); }); }); }); }); -}; \ No newline at end of file +}; diff --git a/test/429.js b/test/429.js new file mode 100644 index 00000000..115884ba --- /dev/null +++ b/test/429.js @@ -0,0 +1,32 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function (gm, dir, finish, GM, imageMagick) { + if (!GM.integration) return finish(); + + const ico = path.join(__dirname, 'fixtures', 'test.ico'); + const buffer = fs.readFileSync(ico); + const stream = fs.createReadStream(ico); + + GM(ico).options({ imageMagick }).size(function (err) { + if (err) { + err.message = 'Failed using ico filename. ' + err.message; + return finish(err); + } + + GM(buffer, 'img.ico').options({ imageMagick }).size(function (err) { + if (err) { + err.message = 'Failed using ico buffer. ' + err.message; + return finish(err); + } + + GM(stream, 'img.ico').options({ imageMagick }).size({bufferStream: true}, function (err) { + if (err) { + err.message = 'Failed using ico stream. ' + err.message; + return finish(err); + } + finish(); + }); + }); + }); +} \ No newline at end of file diff --git a/test/70.js b/test/70.js index 3cf4fe43..5e34bdab 100644 --- a/test/70.js +++ b/test/70.js @@ -1,12 +1,12 @@ -// gm - Copyright Aaron Heckmann (MIT Licensed) -var assert = require('assert') -var times = 16; +const assert = require('assert') +const path = require('path'); -var loading = __dirname + '/fixtures/loading.gif' -var favicon = __dirname + '/fixtures/favicon.png' +var times = 16; +var loading = path.join(__dirname, 'fixtures', 'loading.gif'); +var favicon = path.join(__dirname, 'fixtures', 'favicon.png'); -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); var pending = times/2; @@ -24,8 +24,7 @@ module.exports = function (_, dir, finish, gm) { new Array(times).join('x').split('x').forEach(function (_, i) { ;[loading, favicon].forEach(function (img) { - gm(img) - .size(function edge (err, size) { + gm(img).options({imageMagick}).size(function (err, size) { if (err) return done(err); 'width height'.split(' ').forEach(function (prop) { diff --git a/test/78.js b/test/78.js index 60780668..5dd262c3 100644 --- a/test/78.js +++ b/test/78.js @@ -1,19 +1,16 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var magick = _._options.imageMagick; - var name = magick ? '78-IM' : '78'; - var out = dir + '/' + name; + var name = imageMagick ? '78-IM' : '78'; + var out = path.join(dir, name); _.resize(600, 450, '!').write(out + '.png', function (err) { if (err) return finish(err); - var img = gm(out + '.png'); - if (magick) - img.options({ imageMagick: true }); + var img = gm(out + '.png').options({ imageMagick }); img .crop(70, 70, 100, 100) diff --git a/test/alpha.js b/test/alpha.js index d9fac0f0..67051cf9 100644 --- a/test/alpha.js +++ b/test/alpha.js @@ -1,7 +1,8 @@ -var assert = require('assert'); -var async = require('async'); +const assert = require('assert'); +const Async = require('async'); +const path = require('path'); -module.exports = function (_, dir, finish, gm, im) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); var alphaTypes = [ @@ -17,25 +18,29 @@ module.exports = function (_, dir, finish, gm, im) { "Shape", "Background" ]; + + const edgePath = path.join(dir, 'original.png'); + const failPath = path.join(dir, 'alpha_fail.png'); + // alpha not supported by GM so only test IM - if (!im) { + if (!imageMagick) { assert.throws(function() { - gm(dir + '/edge.png') - .alpha( alphaTypes.pop() ).write(dir+'/alpha_fail.png'); - + gm(edgePath) + .alpha(alphaTypes.pop()) + .write(failPath); }); finish(); } else { - async.eachSeries(alphaTypes,function(alphaType,cb) { - var m = gm(dir + '/edge.png').options({imageMagick: im}).alpha( alphaType ); - var args = m.args(); - assert.equal('convert', args[0]); - assert.equal('-alpha', args[2]); - assert.equal(alphaType, args[3]); + Async.eachSeries(alphaTypes, function(alphaType, cb) { + var m = gm(edgePath).options({imageMagick}).alpha( alphaType ); + var args = m.args(); + assert.equal('convert', args[0]); + assert.equal('-alpha', args[2]); + assert.equal(alphaType, args[3]); - m.write( dir + '/alpha_' + alphaType + '.png', cb); - - },finish); -} + const writePath = path.join(dir, `alpha_${alphaType}.png`); + m.write(writePath, cb); + }, finish); + } } diff --git a/test/append.js b/test/append.js index 7fcadab9..b5603f6d 100644 --- a/test/append.js +++ b/test/append.js @@ -1,14 +1,18 @@ -var assert = require('assert') +const assert = require('assert') +const path = require('path'); -module.exports = function (_, dir, finish, gm) { - var out = require('path').resolve(dir + '/append.jpg'); +module.exports = function (_, dir, finish, gm, imageMagick) { + const out = path.resolve(dir, 'append.jpg'); + const lostPath = path.join(dir, 'lost.png'); + const originalPath = path.join(dir, 'original.jpg'); try { require('fs').unlinkSync(out); } catch (_) {} - var m = gm(dir + '/lost.png') - .append(dir + '/original.jpg', dir + '/original.jpg') + var m = gm(lostPath) + .options({imageMagick}) + .append(originalPath, originalPath) .append() .background('#222') @@ -16,38 +20,39 @@ module.exports = function (_, dir, finish, gm) { assert.equal('convert', args[0]); assert.equal('-background',args[1]); assert.equal('#222',args[2]); - assert.ok(/examples\/imgs\/lost\.png$/.test(args[3])); - assert.ok(/examples\/imgs\/original\.jpg$/,args[4]); - assert.ok(/examples\/imgs\/original\.jpg$/,args[5]); + assert.ok(/lost\.png$/.test(args[3])); + assert.ok(/original\.jpg$/,args[4]); + assert.ok(/original\.jpg$/,args[5]); assert.equal('-append',args[6]); assert.equal('-',args[7]); if (!gm.integration) { - return horizontal(dir, finish, gm); + return horizontal({ dir, finish, gm, originalPath, lostPath, imageMagick }); } m.write(out, function (err) { if (err) return finish(err); - gm(out).size(function (err, size) { + gm(out) + .options({imageMagick}) + .size(function (err, size) { if (err) return finish(err); assert.equal(460, size.width); assert.equal(435, size.height); - horizontal(dir, finish, gm); + horizontal({ dir, finish, gm, originalPath, lostPath, imageMagick }); }) }); } -function horizontal (dir, finish, gm) { - var out = require('path').resolve(dir + '/appendHorizontal.jpg'); +function horizontal ({ dir, finish, gm, originalPath, lostPath, imageMagick }) { + var out = path.resolve(dir, 'appendHorizontal.jpg'); - var m = gm(dir + '/original.jpg') - .append(dir + '/lost.png', true); + var m = gm(originalPath).append(lostPath, true).options({imageMagick}); var args = m.args(); assert.equal('convert', args[0]); - assert.ok(/examples\/imgs\/original\.jpg$/.test(args[1])); - assert.ok(/examples\/imgs\/lost\.png$/.test(args[2])); + assert.ok(/original\.jpg$/.test(args[1])); + assert.ok(/lost\.png$/.test(args[2])); assert.equal('+append',args[3]); assert.equal('-',args[4]); @@ -55,10 +60,9 @@ function horizontal (dir, finish, gm) { return finish(); } - m - .write(out, function (err) { + m.write(out, function (err) { if (err) return finish(err); - gm(out).size(function (err, size) { + gm(out).options({imageMagick}).size(function (err, size) { if (err) return finish(err); assert.equal(697, size.width); assert.equal(155, size.height); diff --git a/test/arc.js b/test/arc.js index 5f54bbb2..f5cda926 100644 --- a/test/arc.js +++ b/test/arc.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -22,11 +22,11 @@ module.exports = function (gm, dir, finish, GM) { assert.equal('-draw', args[10]); assert.equal('arc 80,10 90,20 0,180', args[11]); - if (!GM.integration) - return finish(); + if (!GM.integration) return finish(); + + const arcPath = path.join(dir, 'arc.png'); - m - .write(dir + '/arc.png', function arc (err) { + m.write(arcPath, function arc (err) { finish(err); }); } diff --git a/test/autoOrient.js b/test/autoOrient.js index 677d0c8f..cbeb07ec 100644 --- a/test/autoOrient.js +++ b/test/autoOrient.js @@ -1,34 +1,35 @@ +const assert = require('assert'); +const path = require('path'); -// gm - Copyright Aaron Heckmann (MIT Licensed) - -var assert = require('assert') - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var filename = dir + '/autoOrient.jpg'; + const sidewaysPath = path.join(dir, 'originalSideways.jpg'); - gm(dir + '/originalSideways.jpg').orientation(function (err, o) { + gm(sidewaysPath) + .options({imageMagick}) + .identify(function (err, o) { if (err) return finish(err); - assert.equal('RightTop', o); - assert.ok(!! this.data['Profile-EXIF'], 'No Profile-EXIF data found'); + const geo = imageMagick ? '155x460+0+0' : '155x460'; + assert.equal(geo, o.Geometry); // this image is sideways, but may be auto-oriented by modern OS's // try opening it in a browser to see its true orientation - gm(dir + '/originalSideways.jpg') + gm(sidewaysPath) + .options({imageMagick}) .autoOrient() .stream(function (err, stream) { if (err) return finish(err); - gm(stream).identify(function (err, data) { + gm(stream) + .options({imageMagick}) + .identify(function (err, data) { if (err) return finish(err); - assert.equal('Unknown', data.Orientation); - assert.ok(! this.data['Profile-EXIF'], 'Profile-EXIF still exists'); - assert.equal('460x155', data.Geometry); - + const geo2 = imageMagick ? '460x155+0+0' : '460x155'; + assert.equal(geo2, data.Geometry); finish(err); }) }) diff --git a/test/autoOrientAll.js b/test/autoOrientAll.js index 7f758735..82550872 100644 --- a/test/autoOrientAll.js +++ b/test/autoOrientAll.js @@ -1,13 +1,9 @@ +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); -// gm - Copyright Aaron Heckmann (MIT Licensed) - -var assert = require('assert'), - fs = require('fs'), - os = require('os'); - -module.exports = function (_, dir, finish, gm) { - if (!gm.integration) - return finish(); +module.exports = function (_, dir, finish, gm, imageMagick) { + if (!gm.integration) return finish(); var beforeValues = { 'Landscape_1.jpg': ['TopLeft', 1, '600x450'], @@ -47,7 +43,9 @@ module.exports = function (_, dir, finish, gm) { 'Portrait_8.jpg': '450x600' }; - fs.readdir(dir + '/orientation/', function(err, files) { + const orientationDir = path.join(dir, 'orientation'); + + fs.readdir(orientationDir, function(err, files) { if (err) return finish(err); var originalFiles = files.filter(function(file) { @@ -63,11 +61,11 @@ module.exports = function (_, dir, finish, gm) { function test (filename) { if (!filename) return finish(); - var fileToAutoOrient = dir + '/orientation/' + filename; - var newFilename = fileToAutoOrient + '.oriented.jpg'; - var constant = fileToAutoOrient + '.correct.jpg'; + const fileToAutoOrient = path.join(orientationDir, filename); + const newFilename = fileToAutoOrient + '.oriented.jpg'; + const constant = fileToAutoOrient + '.correct.jpg'; - gm(fileToAutoOrient).orientation(function (err, o) { + gm(fileToAutoOrient).options({imageMagick}).orientation(function (err, o) { if (err) return finish(err); assert.equal(beforeValues[filename][0], o); @@ -76,20 +74,20 @@ module.exports = function (_, dir, finish, gm) { // this image is sideways, but may be auto-oriented by modern OS's // try opening it in a browser to see its true orientation gm(fileToAutoOrient) + .options({ imageMagick }) .autoOrient() .write(newFilename, function autoOrient (err) { if (err) return finish(err); // fs race condition setTimeout(function () { - gm(newFilename).identify(function (err) { + gm(newFilename).options({ imageMagick }).identify(function (err) { if (err) return finish(err); - assert.equal('Unknown', this.data.Orientation); - assert.ok(!this.data['Profile-EXIF']) - assert.equal(afterValues[filename], this.data.Geometry, 'Bad-Geometry for ' + filename); + const afterValue = imageMagick ? `${afterValues[filename]}+0+0` : afterValues[filename]; + assert.equal(afterValue, this.data.Geometry, `Bad-Geometry for ${filename}. Got "${this.data.Geometry}"`); - gm.compare(newFilename, constant, 0.1, function (err, equal) { + gm().options({imageMagick}).compare(newFilename, constant, 0.1, function (err, equal) { if (err) return finish(err); assert.ok(equal); next(); diff --git a/test/autoOrientAndThumb.js b/test/autoOrientAndThumb.js index 9e446a7b..5bc004cf 100755 --- a/test/autoOrientAndThumb.js +++ b/test/autoOrientAndThumb.js @@ -1,25 +1,26 @@ -var assert = require('assert') -var fs = require('fs') +const assert = require('assert') +const path = require('path'); -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var original = dir + '/orientation/Portrait_7.jpg'; - var result = dir + '/autoOrientAndThumb.png'; + var original = path.join(dir, 'orientation', 'Portrait_7.jpg'); + var result = path.join(dir, 'autoOrientAndThumb.png'); - size(original, function (err, origSize) { + size(original, imageMagick, function (err, origSize) { if (err) return finish(err); assert.ok(origSize.width < 610); assert.ok(origSize.height < 460); - var m = gm(original) + gm(original) + .options({imageMagick}) .autoOrient() .thumb(100, 100, result, function (err) { if (err) return finish(err); - size(result, function (err, newSize) { + size(result, imageMagick, function (err, newSize) { if (err) return finish(err); assert.ok(newSize.width < 80); assert.ok(newSize.height < 110); @@ -29,9 +30,8 @@ module.exports = function (_, dir, finish, gm) { }); }); - - function size (file, cb) { - gm(file).identify(function (err, data) { + function size (file, imageMagick, cb) { + gm(file).options({imageMagick}).identify(function (err, data) { if (err) return cb(err); cb(err, data.size); }); diff --git a/test/autoOrientStream.js b/test/autoOrientStream.js index c4177136..4a49ba71 100644 --- a/test/autoOrientStream.js +++ b/test/autoOrientStream.js @@ -2,36 +2,38 @@ // gm - Copyright Aaron Heckmann (MIT Licensed) // This is a copy of `autoOrient.js` using streams -var assert = require('assert') -var fs = require('fs') +const assert = require('assert') +const fs = require('fs') +const path = require('path'); -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var filename = dir + '/autoOrientStream.jpg'; + const filename = path.join(dir, 'autoOrientStream.jpg'); + const sidewaysPathName = path.join(dir, 'originalSideways.jpg'); - gm(fs.createReadStream(dir + '/originalSideways.jpg')).orientation(function (err, o) { + gm(fs.createReadStream(sidewaysPathName)).options({imageMagick}).identify(function (err) { if (err) return finish(err); - assert.equal('RightTop', o); - assert.ok(!! this.data['Profile-EXIF'], 'No Profile-EXIF data found'); + const geo = imageMagick ? '155x460+0+0' : '155x460'; + assert.equal(geo, this.data.Geometry); // this image is sideways, but may be auto-oriented by modern OS's // try opening it in a browser to see its true orientation - gm(fs.createReadStream(dir + '/originalSideways.jpg')) + gm(fs.createReadStream(sidewaysPathName)) + .options({imageMagick}) .autoOrient() .write(filename, function autoOrient (err) { if (err) return finish(err); // fs race condition setTimeout(function () { - gm(filename).identify(function (err) { + gm(filename).options({imageMagick}).identify(function (err) { if (err) return finish(err); - assert.equal('Unknown', this.data.Orientation); - assert.ok(! this.data['Profile-EXIF'], 'Profile-EXIF still exists'); - assert.equal('460x155', this.data.Geometry); + const geo2 = imageMagick ? '460x155+0+0' : '460x155'; + assert.equal(geo2, this.data.Geometry); finish(err); }); diff --git a/test/background.js b/test/background.js index da742225..b3f2268c 100644 --- a/test/background.js +++ b/test/background.js @@ -1,4 +1,5 @@ -var assert =require('assert') +const assert =require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -19,8 +20,9 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/background.jpg', function (err) { + const backgroundPathName = path.join(dir, 'background.jpg'); + + m.write(backgroundPathName, function (err) { finish(err); }); } diff --git a/test/bezier.js b/test/bezier.js index ceedb1fa..0d400b2e 100644 --- a/test/bezier.js +++ b/test/bezier.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -26,7 +26,7 @@ module.exports = function (gm, dir, finish, GM) { return finish(); m - .write(dir + '/bezier.png', function bezier (err) { + .write(path.join(dir, 'bezier.png'), function bezier (err) { finish(err); }); } diff --git a/test/bitdepth.js b/test/bitdepth.js index 3ad476e3..b8578210 100644 --- a/test/bitdepth.js +++ b/test/bitdepth.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/bitdepth.png', function bitdepth (err) { + const outpath = path.join(dir, 'bitdepth.png'); + m.write(outpath, function bitdepth (err) { finish(err); }); } diff --git a/test/blur.js b/test/blur.js index 71bfae81..28285835 100644 --- a/test/blur.js +++ b/test/blur.js @@ -1,5 +1,6 @@ -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +15,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/blur.png', function blur (err) { + const outpath = path.join(dir, 'blur.png'); + m.write(outpath, function blur (err) { finish(err); }); } diff --git a/test/changeFormat.js b/test/changeFormat.js index 1d8b1545..9974a8c3 100644 --- a/test/changeFormat.js +++ b/test/changeFormat.js @@ -1,12 +1,11 @@ - -// gm - Copyright Aaron Heckmann (MIT Licensed) +const path = require('path'); module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - gm - .write(dir + '/changedformat.png', function changeformat (err) { + const outpath = path.join(dir, 'changedformat.png'); + gm.write(outpath, function changeformat (err) { finish(err); }); } diff --git a/test/charcoal.js b/test/charcoal.js index a6f7105d..14a13ed3 100644 --- a/test/charcoal.js +++ b/test/charcoal.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/charcoal.png', function charcoal (err) { + const outpath = path.join(dir, 'charcoal.png'); + m.write(outpath, function charcoal (err) { finish(err); }); } diff --git a/test/chop.js b/test/chop.js index e6d3a5c5..3a14fb72 100644 --- a/test/chop.js +++ b/test/chop.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/chop.png', function chop (err) { + const outpath = path.join(dir, 'chop.png'); + m.write(outpath, function chop (err) { finish(err); }); } diff --git a/test/circle.js b/test/circle.js index 29c4e72e..9b581c91 100644 --- a/test/circle.js +++ b/test/circle.js @@ -1,8 +1,7 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { - var m = gm .blur(8, 4) .stroke("red", 1) @@ -25,8 +24,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/circle.png', function circle (err) { + const outpath = path.join(dir, 'circle.png'); + m.write(outpath, function circle (err) { finish(err); }); } diff --git a/test/colorize.js b/test/colorize.js index 1e6f5f36..d596607d 100644 --- a/test/colorize.js +++ b/test/colorize.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/colorize.png', function colorize (err) { + const outpath = path.join(dir, 'colorize.png'); + m.write(outpath, function colorize (err) { finish(err); }); } diff --git a/test/colors.js b/test/colors.js index 62af990a..d8c98aa5 100644 --- a/test/colors.js +++ b/test/colors.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/colors.png', function colors (err) { + const outpath = path.join(dir, 'colors.png'); + m.write(outpath, function colors (err) { finish(err); }); } diff --git a/test/comment.js b/test/comment.js index 26789d76..22f798a8 100644 --- a/test/comment.js +++ b/test/comment.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/comment.png', function comment (err) { + const outpath = path.join(dir, 'comment.png'); + m.write(outpath, function comment (err) { finish(err); }); } diff --git a/test/compare.js b/test/compare.js index bdcbda79..8d97469b 100644 --- a/test/compare.js +++ b/test/compare.js @@ -1,36 +1,45 @@ -var assert = require('assert'); -var fs = require('fs'); +const path = require('path'); +const fs = require('fs'); -module.exports = function (gm, dir, finish, GM) { +module.exports = function (gm, dir, finish) { // Same image - GM.compare(dir + '/original.jpg', dir + '/original.png', function(err, same) { + const originalJPGFilePath = path.join(dir, 'original.jpg'); + const originalPNGFilePath = path.join(dir, 'original.png'); + + gm.compare(originalJPGFilePath, originalPNGFilePath, function(err, same) { if (err) return finish(err); if (!same) return finish(new Error('Compare should be the same!')); // Compare almost similar images for which ImageMagick // returns a exponent-style floating point number - gm.compare(__dirname + '/fixtures/compare_1.png', __dirname + '/fixtures/compare_2.png', function(err, same, diff) { + const compare1Path = path.join(__dirname, 'fixtures', 'compare_1.png'); + const compare2Path = path.join(__dirname, 'fixtures', 'compare_2.png'); + + gm.compare(compare1Path, compare2Path, function(err, same, diff) { if (err) return finish(err); + if (!same) return finish(new Error('Compare should be the same!')); // Create a new noisy image - gm.noise(0.3).write(dir + '/noise3.png', function (err) { + const noisePath = path.join(dir, 'noise3.png'); + gm.noise(0.3).write(noisePath, function (err) { if (err) return finish(err); - if (!same) return finish(new Error('Compare should be the same!')); - var options = { + const options = { highlightColor: 'yellow', - highlightStyle: 'XOR', - file: dir + '/diff.png', + file: path.join(dir, `compare-test-${Date.now()}.png`), tolerance: 0.001 }; // Compare these images and write to a file. - GM.compare(dir + '/original.jpg', dir + '/noise3.png', options, function(err) { + gm.compare(originalJPGFilePath, noisePath, options, function(err) { if (err) return finish(err); - fs.exists(options.file, function(exists) { - if (exists) finish(); - else finish(new Error('Diff file does not exist.')); + fs.access(options.file, fs.constants.F_OK, function(err) { + if (err) { + finish(new Error('Diff file does not exist.')); + } else { + fs.unlink(options.file, () => finish()); + } }); }); }); diff --git a/test/composite.js b/test/composite.js index 6cc278f3..8b47dd5f 100644 --- a/test/composite.js +++ b/test/composite.js @@ -1,20 +1,23 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { - gm.source = __dirname + '/fixtures/compare_1.png'; - var a = gm.composite(__dirname + '/fixtures/favicon.png') + const sourcePath = path.join(__dirname, 'fixtures', 'compare_1.png'); + gm.source = sourcePath; + + const faviconPath = path.join(__dirname, 'fixtures', 'favicon.png'); + const a = gm.composite(faviconPath) - var args = a.args(); + const args = a.args(); assert.equal('composite', args[0]); - assert.equal(__dirname + '/fixtures/favicon.png', args[1]); - assert.equal(__dirname + '/fixtures/compare_1.png', args[2]); + assert.equal(faviconPath, args[1]); + assert.equal(sourcePath, args[2]); if (!GM.integration) return finish(); - a - .write(dir + '/composite.png', function(err) { + const destPath = path.join(dir, 'composite.png'); + a.write(destPath, function(err) { finish(err); }); } diff --git a/test/contrast.js b/test/contrast.js index 70e10c02..a37d8608 100644 --- a/test/contrast.js +++ b/test/contrast.js @@ -1,21 +1,19 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { + const m = gm.contrast(2); - var m = gm - .contrast(2); - - var args = m.args(); + const args = m.args(); assert.equal('convert', args[0]); assert.equal('+contrast', args[2]); assert.equal('+contrast', args[3]); - if (!GM.integration) - return finish(); + if (!GM.integration) return finish(); + + const destPath = path.join(dir, 'contrast.png'); - m - .write(dir + '/contrast.png', function contrast (err) { + m.write(destPath, function contrast (err) { finish(err); }); } diff --git a/test/crop.js b/test/crop.js index f293b3d1..07195eb5 100644 --- a/test/crop.js +++ b/test/crop.js @@ -1,27 +1,25 @@ +const assert = require('assert') +const path = require('path'); -var assert = require('assert') +module.exports = function (gm, dir, finish, GM, imageMagick) { + const m = gm.crop(200, 155, 300, 0); -module.exports = function (gm, dir, finish, GM) { - - var m = gm - .crop(200, 155, 300, 0); - - var args = m.args(); + const args = m.args(); assert.equal('convert', args[0]); assert.equal('-crop', args[2]); assert.equal('200x155+300+0', args[3]); - var m2 = GM(dir + '/image.png') - .crop(200, 155, 300, 0, true); + const imagePath = path.join(dir, 'image.png'); + const m2 = GM(imagePath).options({ imageMagick }).crop(200, 155, 300, 0, true); - var args2 = m2.args(); + const args2 = m2.args(); assert.equal('200x155+300+0%', args2[3]); if (!GM.integration) return finish(); - m - .write(dir + '/crop.png', function crop (err) { + const destPath = path.join(dir, 'crop.png'); + m.write(destPath, function crop (err) { finish(err); }); } diff --git a/test/cycle.js b/test/cycle.js index b1101b6f..15c67925 100644 --- a/test/cycle.js +++ b/test/cycle.js @@ -1,12 +1,10 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { + const m = gm.cycle(4); - var m = gm - .cycle(4); - - var args = m.args(); + const args = m.args(); assert.equal('convert', args[0]); assert.equal('-cycle', args[2]); assert.equal(4, args[3]); @@ -14,8 +12,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/cycle.png', function cycle (err) { + const destPath = path.join(dir, 'cycle.png'); + m.write(destPath, function cycle (err) { finish(err); }); } diff --git a/test/densityGm.js b/test/densityGm.js index 40c8ed32..ceab256b 100644 --- a/test/densityGm.js +++ b/test/densityGm.js @@ -1,28 +1,27 @@ +const assert = require('assert') +const path = require('path'); -var assert = require('assert'); - -module.exports = function (gm, dir, finish, GM) { - 'use strict'; - - // a two magic numbers +module.exports = function (gm, dir, finish, GM, imageMagick) { var NUMBER = 100; var NUMBER2 = 200; - var g = gm.density(NUMBER, NUMBER2); - var gArgs = g.args(); - assert.equal('convert', gArgs[0]); assert.equal('-density', gArgs[1]); assert.equal(NUMBER + 'x' + NUMBER2, gArgs[2]); - if (gm._options.imageMagick) - return finish(); + if (imageMagick) { + // graphicsmagick does not support density with two arguments + var imArgs = GM().options({imageMagick}).density(NUMBER).args(); + assert.equal('convert', imArgs[0]); + assert.equal('-density', imArgs[1]); + assert.equal(NUMBER, imArgs[2]); + } - if (!GM.integration) - return finish(); + if (!GM.integration) return finish(); - g.write(dir + '/density.png', function density (err) { + const destPath = path.join(dir, 'density.png'); + g.write(destPath, function density (err) { finish(err); }); }; diff --git a/test/densityIm.js b/test/densityIm.js deleted file mode 100644 index 82dd0624..00000000 --- a/test/densityIm.js +++ /dev/null @@ -1,28 +0,0 @@ - -var assert = require('assert'); - -module.exports = function (gm, dir, finish, GM) { - 'use strict'; - - // a magic number - var NUMBER = 100; - - // image magic version - var im = gm.options({imageMagick: true}).density(NUMBER); - - var imArgs = im.args(); - - assert.equal('convert', imArgs[0]); - assert.equal('-density', imArgs[1]); - assert.equal(NUMBER, imArgs[2]); - - if (gm._options.imageMagick) - return finish(); - - if (!GM.integration) - return finish(); - - im.write(dir + '/density.png', function density (err) { - finish(err); - }); -}; diff --git a/test/despeckle.js b/test/despeckle.js index e3e9dec3..0d5d67ce 100644 --- a/test/despeckle.js +++ b/test/despeckle.js @@ -1,10 +1,8 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { - - var m = gm - .despeckle(); + var m = gm.despeckle(); var args = m.args(); assert.equal('convert', args[0]); @@ -13,8 +11,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/despeckle.png', function despeckle (err) { + const destPath = path.join(dir, 'despeckle.png'); + m.write(destPath, function despeckle (err) { finish(err); }); } diff --git a/test/dispose.js b/test/dispose.js new file mode 100644 index 00000000..67b9598b --- /dev/null +++ b/test/dispose.js @@ -0,0 +1,47 @@ +const assert = require('assert') +const path = require('path'); + +module.exports = function (img, dir, finish, gm, imageMagick) { + var EventEmitter = require('events').EventEmitter; + EventEmitter.prototype._maxListeners = 100; + + assert.equal(undefined, gm.prototype._options.disposers); + assert.equal(undefined, img._options.disposers); + + var emitter = new EventEmitter(); + + var disposer = { + emitter: emitter, + events: ['pleaseDispose', 'readyToDispose'] + }; + + var g = gm('test').options({ disposers: [ disposer ], imageMagick }); + assert.deepEqual([disposer], g._options.disposers); + + var sub = gm.subClass({ disposers: [ disposer ], imageMagick }); + assert.deepEqual([disposer], sub.prototype._options.disposers); + + if (!gm.integration) { + return finish(); + } + + const photoPath = path.join(dir, 'photo.JPG'); + const disposePath = path.join(dir, 'dispose.png'); + + gm(photoPath).options({ disposers: [ disposer ], imageMagick }) + .thumb(1000, 1000, disposePath, function (err) { + assert.ok(err, "Expecting a disposed error"); + }); + + emitter.emit('pleaseDispose'); + + noDispose(); + + function noDispose() { + gm(photoPath).options({ disposers: [ disposer ], imageMagick }) + .thumb(1000, 1000, disposePath, function (err) { + finish(err); + }); + emitter.emit('disposeOK'); + } +} diff --git a/test/dither.js b/test/dither.js index 97ad31ff..ca53a179 100644 --- a/test/dither.js +++ b/test/dither.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { if (gm._options.imageMagick) @@ -15,7 +15,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - g.write(dir + '/dither.png', function dither (err) { + const destPath = path.join(dir, 'dither.png'); + g.write(destPath, function dither (err) { finish(err); }); } diff --git a/test/edge.js b/test/edge.js index 1c642000..22f04ebf 100644 --- a/test/edge.js +++ b/test/edge.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/edge.png', function edge (err) { + const destPath = path.join(dir, 'edge.png'); + m.write(destPath, function edge (err) { finish(err); }); } diff --git a/test/ellipse.js b/test/ellipse.js index 8f5a34b7..60bd6d15 100644 --- a/test/ellipse.js +++ b/test/ellipse.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -22,8 +22,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/ellipse.png', function ellipse (err) { + const destPath = path.join(dir, 'ellipse.png'); + m.write(destPath, function ellipse (err) { finish(err); }); } diff --git a/test/emboss.js b/test/emboss.js index 287d652a..1a831afd 100644 --- a/test/emboss.js +++ b/test/emboss.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/emboss.png', function emboss (err) { + const destPath = path.join(dir, 'emboss.png'); + m.write(destPath, function emboss (err) { finish(err); }); } diff --git a/test/enhance.js b/test/enhance.js index 2e3d8845..3f9a285e 100644 --- a/test/enhance.js +++ b/test/enhance.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/enhance.png', function enhance (err) { + const destPath = path.join(dir, 'enhance.png'); + m.write(destPath, function enhance (err) { finish(err); }); } diff --git a/test/equalize.js b/test/equalize.js index f127cc74..e8c506c3 100644 --- a/test/equalize.js +++ b/test/equalize.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/equalize.png', function equalize (err) { + const destPath = path.join(dir, 'equalize.png'); + m.write(destPath, function equalize (err) { finish(err); }); } diff --git a/test/extent.js b/test/extent.js index 70ef12a9..2c8a0daa 100644 --- a/test/extent.js +++ b/test/extent.js @@ -1,4 +1,5 @@ -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -16,8 +17,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/extent.png', function resize (err) { + const destPath = path.join(dir, 'extent.png'); + m.write(destPath, function resize (err) { finish(err); }); } diff --git a/test/fixtures/iptc-multiple.jpg b/test/fixtures/iptc-multiple.jpg new file mode 100644 index 00000000..db25eb84 Binary files /dev/null and b/test/fixtures/iptc-multiple.jpg differ diff --git a/test/fixtures/test.ico b/test/fixtures/test.ico new file mode 100644 index 00000000..78713f95 Binary files /dev/null and b/test/fixtures/test.ico differ diff --git a/test/flatten.js b/test/flatten.js index 9cdaee86..46e04c73 100644 --- a/test/flatten.js +++ b/test/flatten.js @@ -1,10 +1,16 @@ -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); -module.exports = function (img, dir, finish, gm) { - var changed = gm('whatever.png').gravity("Souths") - assert.equal(changed._out[1], 'NorthWest'); +module.exports = function (_, dir, finish, gm, imageMagick) { + // graphicsmagick considers PSD broken + // http://www.graphicsmagick.org/NEWS.html#may-30-2016 + if (!imageMagick) { + return finish(); + } - var m = gm(dir + '/layers.psd') + const layersPath = path.join(dir, 'layers.psd'); + var m = gm(layersPath) + .options({ imageMagick }) .flatten(); var args = m.args(); @@ -14,8 +20,8 @@ module.exports = function (img, dir, finish, gm) { if (!gm.integration) return finish(); - m - .write(dir + '/unlayered.jpg', function (err) { + const destPath = path.join(dir, 'unlayered.jpg'); + m.write(destPath, function (err) { finish(err); }); } diff --git a/test/flip.js b/test/flip.js index d480d555..f440132a 100644 --- a/test/flip.js +++ b/test/flip.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/flip.png', function flip (err) { + const destPath = path.join(dir, 'flip.png'); + m.write(destPath, function flip (err) { finish(err); }); } diff --git a/test/flop.js b/test/flop.js index 99e7975d..91c49b41 100644 --- a/test/flop.js +++ b/test/flop.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/flop.png', function flop (err) { + const destPath = path.join(dir, 'flop.png'); + m.write(destPath, function flop (err) { finish(err); }); } diff --git a/test/fromBuffer.js b/test/fromBuffer.js index 7047f8fb..c5ab2dc5 100644 --- a/test/fromBuffer.js +++ b/test/fromBuffer.js @@ -1,15 +1,15 @@ -var assert = require('assert') -var fs = require('fs') +const assert = require('assert'); +const path = require('path'); +const fs = require('fs') -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { - var original = dir + '/original.jpg'; - var result = dir + '/fromBuffer.png'; + const original = path.join(dir, 'original.jpg'); + const result = path.join(dir, 'fromBuffer.png'); var buf = fs.readFileSync(original); - var m = gm(buf) - .rotate('red', 30); + var m = gm(buf).options({imageMagick}).rotate('red', 30); var args = m.args(); assert.equal('convert', args[0]); @@ -22,17 +22,16 @@ module.exports = function (_, dir, finish, gm) { if (!gm.integration) return finish(); - m - .write(result, function crop (err) { + m.write(result, function crop (err) { if (err) return finish(err); // tolerance defaults to 0.4 - gm.compare(original, result, function (err, equal) { + m.compare(original, result, function (err, equal) { if (err) return finish(err); assert.ok(equal); // accepts tolerance argument - gm.compare(original, result, 0.1, function (err, equal, equality, raw) { + m.compare(original, result, 0.1, function (err, equal, equality, raw) { if (err) return finish(err); assert.ok(!equal); assert.ok(equality > 0.1); diff --git a/test/gamma.js b/test/gamma.js index 95b1fe24..61d3adf5 100644 --- a/test/gamma.js +++ b/test/gamma.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/gamma.png', function gamma (err) { + const destPath = path.join(dir, 'gamma.png'); + m.write(destPath, function gamma (err) { finish(err); }); } diff --git a/test/geometry.js b/test/geometry.js index 4dbbbcdd..3df00f39 100644 --- a/test/geometry.js +++ b/test/geometry.js @@ -1,16 +1,16 @@ var assert = require('assert') -module.exports = function (gm, dir, finish, GM) { - var a = GM("dummy").geometry("asdf"); // Custom geometry command +module.exports = function (_, __, finish, GM, imageMagick) { + var a = GM("dummy").options({imageMagick}).geometry("asdf"); // Custom geometry command var args = a.args(); assert.equal('-geometry', args[2]); assert.equal('asdf', args[3]); - var b = GM("dummy").geometry("", 100) + var b = GM("dummy").options({imageMagick}).geometry("", 100); var args = b.args(); assert.equal('-geometry', args[2]); assert.equal('x100', args[3]); // Keep-aspect-ratio command - return finish(); + return finish(); } diff --git a/test/getterColor.js b/test/getterColor.js index 511f197d..793f43fe 100644 --- a/test/getterColor.js +++ b/test/getterColor.js @@ -1,11 +1,12 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - gm(dir + '/blue.gif').color(function (err, color) { + const destPath = path.join(dir, 'blue.gif'); + gm(destPath).options({imageMagick}).color(function (err, color) { if (err) return finish(err); assert.equal(1, color) diff --git a/test/getterFormatGIF.js b/test/getterFormatGIF.js index e11895be..6a3fcb6f 100644 --- a/test/getterFormatGIF.js +++ b/test/getterFormatGIF.js @@ -1,11 +1,12 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert'); - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - gm(dir + '/original.gif') + const destPath = path.join(dir, 'original.gif'); + gm(destPath).options({imageMagick}) .format(function (err, type) { if (err) return finish(err); diff --git a/test/getterIdentify.js b/test/getterIdentify.js index 9194f18f..30f5e54f 100755 --- a/test/getterIdentify.js +++ b/test/getterIdentify.js @@ -1,31 +1,30 @@ - -var assert = require('assert') -var os = require('os') +const assert = require('assert'); +const path = require('path'); +const os = require('os') var isLinux = os.platform() === 'linux' // Be more lax with the errors if we're on linux -var errorFactor = isLinux ? 10 : 1 +var errorFactor = isLinux ? 10 : 1.1 -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var im = _._options.imageMagick; + const photoPath = path.join(dir, 'photo.JPG'); + var test = gm(photoPath).options({ imageMagick }); - var test = gm(dir + '/photo.JPG'); - if (im) test.options({ imageMagick: true }); test.identify(function (err) { if (err) return finish(err); var d = this.data; - if (im) { + if (imageMagick) { assert.equal(d.Orientation, 'TopLeft'); assert.equal(d['Geometry'], '430x488+0+0'); assert.equal(d['Print size'], '5.97222x6.77778'); - assert.equal(d['Channel depth'].red, '8-bit'); - assert.equal(d['Channel depth'].green, '8-bit'); - assert.equal(d['Channel statistics'].Red.min, '0 (0)'); + assert.ok(d['Channel depth'].Red || d['Channel depth'].red); + assert.ok(d['Channel depth'].Green || d['Channel depth'].green); + assert.ok(/0\s+\(0\)/.test(d['Channel statistics'].Red.min)); var sd = d['Channel statistics'].Red['standard deviation'].split(' ') var sd1 = parseFloat(sd[0]) @@ -34,7 +33,7 @@ module.exports = function (_, dir, finish, gm) { assert.ok(sd2 && Math.abs(sd2 - 0.281208) < .001 * errorFactor) var imageStat = parseFloat(d['Image statistics'].Overall.kurtosis) - assert.ok(imageStat && Math.abs(imageStat - -1.09331) < .001 * errorFactor) + assert.ok(imageStat); if (!isLinux) { // This is undefined in Linux @@ -64,20 +63,19 @@ module.exports = function (_, dir, finish, gm) { }); function gif (callback) { - var test = gm(dir + '/blue.gif'); - if (im) test.options({ imageMagick: true }); + const bluePath = path.join(dir, 'blue.gif'); + var test = gm(bluePath).options({ imageMagick }); + test.identify(function (err) { if (err) return finish(err); - if (im) { + if (imageMagick) { if (!isLinux) { assert.equal(1, this.data.color); } - var blueWorks = this.data.Colormap['0'] == '( 0, 0,255) #0000FF blue'; - var blackWorks = this.data.Colormap['1'] == '( 0, 0, 0) #000000 black'; - assert.ok(blueWorks); - assert.ok(blackWorks); + assert.ok(/blue/.test(this.data.Colormap['0'])); + assert.ok(/black/.test(this.data.Colormap['1'])); } else { if (!isLinux) { @@ -101,11 +99,12 @@ module.exports = function (_, dir, finish, gm) { } function pattern () { - var test = gm(dir + '/blue.gif'); + const bluePath = path.join(dir, 'blue.gif'); + var test = gm(bluePath); var format = '%f: %m, %wx%h'; var value = 'blue.gif: GIF, 100x200'; - if (im) test.options({ imageMagick: true }); + test.options({ imageMagick }); test.identify(format, function (err, result) { if (err) return finish(err); diff --git a/test/getterIptc.js b/test/getterIptc.js index 7d66b13a..89fecf87 100644 --- a/test/getterIptc.js +++ b/test/getterIptc.js @@ -1,21 +1,19 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var im = _._options.imageMagick; - - var test = gm(__dirname + '/fixtures/iptc.jpg'); - if (im) test.options({ imageMagick: true }); + const iptcPath = path.join(__dirname, 'fixtures', 'iptc.jpg'); + var test = gm(iptcPath).options({imageMagick}) test.identify(function (err) { if (err) return finish(err); var d = this.data; - if (im) { + if (imageMagick) { var iptc = d['Profiles'] && d['Profiles']['Profile-iptc']; assert.equal(iptc['Caption[2,120]'], 'Some caption with colon space: for example'); } diff --git a/test/getterMultipleIptc.js b/test/getterMultipleIptc.js new file mode 100644 index 00000000..4b558b2d --- /dev/null +++ b/test/getterMultipleIptc.js @@ -0,0 +1,29 @@ +const assert = require('assert'); +const path = require('path'); + +module.exports = function (_, dir, finish, gm, imageMagick) { + if (!gm.integration) + return finish(); + + const iptcPath = path.join(__dirname, 'fixtures', 'iptc-multiple.jpg'); + var test = gm(iptcPath).options({imageMagick}) + + test.identify(function (err) { + if (err) return finish(err); + + var d = this.data; + + if (imageMagick) { + var iptc = d['Profiles'] && d['Profiles']['Profile-iptc']; + var keywords = iptc['Keyword[2,25]']; + assert(Array.isArray(keywords)); + assert.equal(keywords.length, 5); + + // just make sure another value + assert(! Array.isArray(iptc['Headline[2,105]'])); + } + + finish(); + }); + +} diff --git a/test/getterSize.js b/test/getterSize.js index 52c673d0..2a480320 100644 --- a/test/getterSize.js +++ b/test/getterSize.js @@ -1,7 +1,7 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert'); - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); @@ -16,20 +16,21 @@ module.exports = function (_, dir, finish, gm) { }) function sizeJPEG(done) { - gm(dir + '/original.jpg') - .size(function gettersize (err, size) { + const originalPath = path.join(dir, 'original.jpg'); + gm(originalPath).options({imageMagick}).size(function gettersize (err, size) { if (err) return done(err); assert.equal(size.width, 460); assert.equal(size.height, 155); - gm(dir + '/identifyParseErr.jpg').size(done); + const identifyParseErrPath = path.join(dir, 'identifyParseErr.jpg'); + gm(identifyParseErrPath).options({imageMagick}).size(done); }); } function sizeGIF(done) { - gm(dir + '/original.gif') - .size(function (err, size) { + const originalGifPath = path.join(dir, 'original.gif'); + gm(originalGifPath).options({imageMagick}).size(function (err, size) { if (err) return done(err); assert.equal(size.width, 192) @@ -40,8 +41,8 @@ module.exports = function (_, dir, finish, gm) { } function sizePNG(done) { - gm(dir + '/original.png') - .size(function (err, size) { + const originalPngPath = path.join(dir, 'original.png'); + gm(originalPngPath).options({imageMagick}).size(function (err, size) { if (err) return done(err); assert.equal(size.width, 460) diff --git a/test/gh-17.js b/test/gh-17.js index ce6e9181..ebb0c40c 100644 --- a/test/gh-17.js +++ b/test/gh-17.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { var m = gm @@ -16,8 +16,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/cropresize.png', function crop (err) { + const destPath = path.join(dir, 'cropresize.png'); + m.write(destPath, function crop (err) { finish(err); }); } diff --git a/test/gifFrame.js b/test/gifFrame.js index 041c6c63..89ee1b0e 100644 --- a/test/gifFrame.js +++ b/test/gifFrame.js @@ -1,13 +1,13 @@ +const path = require('path'); -var fs = require('fs'); -var assert =require('assert') - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - gm(dir + '/original.gif[0]') - .write(dir + '/gifFrame.jpg', function gifFrame (err){ + const originalGifPath = path.join(dir, 'original.gif[0]'); + const gifFramePath = path.join(dir, 'gifFrame.jpg'); + gm(originalGifPath).options({imageMagick}) + .write(gifFramePath, function gifFrame (err){ finish(err); }); } diff --git a/test/gifFrameIdentify.js b/test/gifFrameIdentify.js index b2f46358..d3c3d7bd 100644 --- a/test/gifFrameIdentify.js +++ b/test/gifFrameIdentify.js @@ -1,9 +1,9 @@ +const assert = require('assert') +const path = require('path'); -var assert = require('assert') -var fs = require('fs'); - -module.exports = function (_, dir, finish, gm) { - var m = gm(dir + '/original.gif[0]') +module.exports = function (_, dir, finish, gm, imageMagick) { + const originalGifPath = path.join(dir, 'original.gif[0]'); + var m = gm(originalGifPath).options({imageMagick}); if (!gm.integration) return finish(); diff --git a/test/gifFrameStream.js b/test/gifFrameStream.js index 5e1d9122..6d79c1e9 100644 --- a/test/gifFrameStream.js +++ b/test/gifFrameStream.js @@ -1,9 +1,11 @@ +const assert = require('assert') +const path = require('path'); +const fs = require('fs'); -var assert = require('assert') -var fs = require('fs'); - -module.exports = function (_, dir, finish, gm) { - var m = gm(fs.createReadStream(dir + '/original.gif'), "original.gif[0]") +module.exports = function (_, dir, finish, gm, imageMagick) { + const originalGifPath = path.join(dir, 'original.gif'); + const readStream = fs.createReadStream(originalGifPath); + const m = gm(readStream, "original.gif[0]").options({imageMagick}); var args = m.args(); assert.equal('convert', args[0]); @@ -12,8 +14,8 @@ module.exports = function (_, dir, finish, gm) { if (!gm.integration) return finish(); - m - .write(dir + '/gifFrameStream.jpg', function gifFrame (err){ + const destPath = path.join(dir, 'gifFrameStream.jpg'); + m.write(destPath, function gifFrame (err){ finish(err); }); } diff --git a/test/gravity.js b/test/gravity.js index 89515d8f..20dc69e1 100644 --- a/test/gravity.js +++ b/test/gravity.js @@ -1,4 +1,5 @@ -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (img, dir, finish, gm) { var changed = gm('whatever.png').gravity("Souths") @@ -24,8 +25,8 @@ module.exports = function (img, dir, finish, gm) { if (!gm.integration) return finish(); - m - .write(dir + '/gravity.png', function resize (err) { + const destPath = path.join(dir, 'gravity.png'); + m.write(destPath, function resize (err) { finish(err); }); } diff --git a/test/implode.js b/test/implode.js index 1b8577cc..1681220d 100644 --- a/test/implode.js +++ b/test/implode.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/implode.png', function implode (err) { + const destPath = path.join(dir, 'implode.png'); + m.write(destPath, function implode (err) { finish(err); }); } diff --git a/test/index.js b/test/index.js index ebb88856..39f05082 100644 --- a/test/index.js +++ b/test/index.js @@ -1,36 +1,34 @@ - -// gm - Copyright Aaron Heckmann (MIT Licensed) - -var async = require('async'); -var dir = __dirname + '/../examples/imgs'; -var gm = require('../'); -var assert = require('assert'); -var gleak = require('gleak')(); -var fs = require('fs'); - -gleak.whitelist.push(clearImmediate); -gleak.whitelist.push(setImmediate); - -var only = process.argv.slice(2); +const cp = require('child_process'); +const path = require('path'); +const Async = require('async'); +const dir = path.join(__dirname, '..', 'examples', 'imgs'); +const gm = require('..'); +const fs = require('fs'); +const os = require('os'); + +const only = process.argv.slice(2); gm.integration = !! ~process.argv.indexOf('--integration'); if (gm.integration) only.shift(); -var files = fs.readdirSync(__dirname).filter(filter); +let files = fs.readdirSync(__dirname).filter(filter); +if (files.length === 0) { + console.log('No tests found matching', only); +} function filter (file) { if (!/\.js$/.test(file)) return false; if ('index.js' === file) return false; if (only.length && !~only.indexOf(file)) return false; - var filename = __dirname + '/' + file; + var filename = path.join(__dirname, file); if (!fs.statSync(filename).isFile()) return false; return true; } -function test (imagemagick) { - if (imagemagick) - return gm(dir + '/original.jpg').options({ imageMagick: true }); - return gm(dir + '/original.jpg'); +const originalPathName = path.join(dir, 'original.jpg'); + +function test (imageMagick) { + return gm(originalPathName).options({ imageMagick }); } function finish (filename) { @@ -39,19 +37,43 @@ function finish (filename) { console.error('\n\nError occured with file: ' + filename); throw err; } + } +} - process.stdout.write('\033[2K'); - process.stdout.write('\033[0G'); - process.stdout.write('pending ' + (q.length()+q.running())); +function isGraphicsMagickInstalled() { + try { + cp.execSync('gm -version'); + return true; + } catch (_) { + return false; } } -process.stdout.write('\033[?25l'); +function isConvertInstalled() { + try { + cp.execSync('convert -version'); + return true; + } catch (_) { + return false; + } +} -var q = async.queue(function (task, callback) { +function isMagickInstalled() { + try { + cp.execSync('magick -version'); + return true; + } catch (_) { + return false; + } +} + +const isWindows = () => os.platform() === 'win32'; + +var q = Async.queue(function (task, callback) { var filename = task.filename; var im = task.imagemagick; + console.log(`Testing ${filename} ..`); require(filename)(test(im), dir, function (err) { finish(filename)(err); callback(); @@ -59,29 +81,42 @@ var q = async.queue(function (task, callback) { }, 1); q.drain = function(){ - -process.stdout.write('\033[?25h'); - process.stdout.write('\033[2K'); - process.stdout.write('\033[0G'); - var leaks = gleak.detect(); - assert.equal(0, leaks.length, "global leaks detected: " + leaks); - console.error("\n\u001B[32mAll tests passed\u001B[0m"); + console.log("\n\u001B[32mAll tests passed\u001B[0m"); }; files = files.map(function (file) { - return __dirname + '/' + file -}) - -files.forEach(function (file) { - q.push({ - imagemagick: false, - filename: file - }) -}) - -files.forEach(function (file) { - q.push({ - imagemagick: true, - filename: file - }) -}) + return path.join(__dirname, file); +}); + +if (isGraphicsMagickInstalled()) { + console.log('gm is installed'); + files.forEach(function (filename) { + q.push({ + imagemagick: false, + filename + }) + }); +} + +if (!isWindows() && isConvertInstalled()) { + // windows has a different convert binary + + console.log('convert is installed'); + files.forEach(function (filename) { + q.push({ + imagemagick: true, + filename + }) + }); +} + +if (isMagickInstalled()) { + console.log('magick is installed'); + + files.forEach(function (filename) { + q.push({ + imagemagick: '7+', + filename + }) + }); +} \ No newline at end of file diff --git a/test/inputIs.js b/test/inputIs.js index 37aecf7a..abb4708b 100644 --- a/test/inputIs.js +++ b/test/inputIs.js @@ -1,13 +1,12 @@ - -// gm - Copyright Aaron Heckmann (MIT Licensed) - -var assert = require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (_, dir, finish, gm) { var err; try { - var gif = gm('/path/to/blah.gif'); + const blahPath = path.join('path', 'to', 'blah.gif') ; + var gif = gm(blahPath); assert.equal(true, gif.inputIs('gif')); assert.equal(false, gif.inputIs('jpg')); assert.equal(false, gif.inputIs('crazy')); @@ -17,7 +16,8 @@ module.exports = function (_, dir, finish, gm) { assert.equal(false, png.inputIs('gif')); assert.equal(false, png.inputIs('tif')); - var jpg = gm('super/duper.jpeg'); + const jpgPath = path.join('super', 'duper.jpeg') + var jpg = gm(jpgPath); assert.equal(true, jpg.inputIs('jpg')); assert.equal(true, jpg.inputIs('jpeg')); assert.equal(false, jpg.inputIs('gif')); diff --git a/test/interlace.js b/test/interlace.js index 2239831e..20b17cb1 100644 --- a/test/interlace.js +++ b/test/interlace.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/edge.png', function edge (err) { + const destPath = path.join(dir, 'interlace.png'); + m.write(destPath, function interlace (err) { finish(err); }); } diff --git a/test/label.js b/test/label.js index b23e2ca9..52138287 100644 --- a/test/label.js +++ b/test/label.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/label.png', function label (err) { + const destPath = path.join(dir, 'label.png'); + m.write(destPath, function label (err) { finish(err); }); } diff --git a/test/limit.js b/test/limit.js index b725d5f0..ff7a99f8 100644 --- a/test/limit.js +++ b/test/limit.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -19,8 +19,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/limit.png', function limit (err) { + const destPath = path.join(dir, 'limit.png'); + m.write(destPath, function limit (err) { finish(err); }); } diff --git a/test/line.js b/test/line.js index bfba6f92..635e5cde 100644 --- a/test/line.js +++ b/test/line.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -21,8 +21,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/line.png', function line (err) { + const destPath = path.join(dir, 'line.png'); + m.write(destPath, function line (err) { finish(err); }); } diff --git a/test/lower.js b/test/lower.js index 230ca55d..972b8e73 100644 --- a/test/lower.js +++ b/test/lower.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/lower.png', function lower (err) { + const destPath = path.join(dir, 'lower.png'); + m.write(destPath, function lower (err) { finish(err); }); } diff --git a/test/magnify.js b/test/magnify.js index 1fbb4be1..4a150cce 100644 --- a/test/magnify.js +++ b/test/magnify.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -17,8 +17,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/magnify.png', function magnify (err) { + const destPath = path.join(dir, 'magnify.png'); + m.write(destPath, function magnify (err) { finish(err); }); } diff --git a/test/median.js b/test/median.js index e6a90389..7445df17 100644 --- a/test/median.js +++ b/test/median.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/median.png', function media (err) { + const destPath = path.join(dir, 'median.png'); + m.write(destPath, function media (err) { finish(err); }); } diff --git a/test/minify.js b/test/minify.js index d34ed544..dd6388d1 100644 --- a/test/minify.js +++ b/test/minify.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { if (gm._options.imageMagick) return finish(); @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/minify.png', function minify (err) { + const destPath = path.join(dir, 'minify.png'); + m.write(destPath, function minify (err) { finish(err); }); } diff --git a/test/minifyIM.js b/test/minifyIM.js index b7307962..d498a657 100644 --- a/test/minifyIM.js +++ b/test/minifyIM.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { var m = gm.minify(); @@ -11,11 +11,12 @@ module.exports = function (gm, dir, finish, GM) { if(gm._options.imageMagick) { assert.throws( function() { - m.write(dir + '/minify.png', function minify (err) { throw err;}) + const destPath = path.join(dir, 'minify.png'); + m.write(destPath, function minify (err) { throw err;}) }, Error ); } - return finish(); + return finish(); } \ No newline at end of file diff --git a/test/modulate.js b/test/modulate.js index 5c5c62e8..02e2cb8a 100644 --- a/test/modulate.js +++ b/test/modulate.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/modulate.png', function modulate (err) { + const destPath = path.join(dir, 'modulate.png'); + m.write(destPath, function modulate (err) { finish(err); }); } diff --git a/test/monochrome.js b/test/monochrome.js index 733f2769..79975fa0 100644 --- a/test/monochrome.js +++ b/test/monochrome.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -13,8 +13,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/monochrome.png', function monochrome (err) { + const destPath = path.join(dir, 'monochrome.png'); + m.write(destPath, function monochrome (err) { finish(err); }); } diff --git a/test/montage.js b/test/montage.js index 8c126712..0b3eef47 100644 --- a/test/montage.js +++ b/test/montage.js @@ -1,20 +1,24 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { - gm.source = __dirname + '/fixtures/compare_1.png'; - var a = gm.montage(__dirname + '/fixtures/favicon.png') + const fixturesPath = path.join(__dirname, 'fixtures'); + const srcPath = path.join(fixturesPath, 'compare_1.png'); + + gm.source = srcPath; + const faviconPath = path.join(fixturesPath, 'favicon.png'); + var a = gm.montage(faviconPath); var args = a.args(); assert.equal('montage', args[0]); - assert.equal(__dirname + '/fixtures/favicon.png', args[1]); - assert.equal(__dirname + '/fixtures/compare_1.png', args[2]); + assert.equal(faviconPath, args[1]); + assert.equal(srcPath, args[2]); if (!GM.integration) return finish(); - a - .write(dir + '/montage.png', function(err) { + const destPath = path.join(dir, 'montage.png'); + a.write(destPath, function(err) { finish(err); }); } diff --git a/test/morph-more.js b/test/morph-more.js index fdbd851d..63a1cc98 100644 --- a/test/morph-more.js +++ b/test/morph-more.js @@ -1,4 +1,4 @@ -var assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -7,8 +7,12 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); + const morpherPath = path.join(dir, 'morpher.jpg'); + const originalPath = path.join(dir, 'original.png'); + const morphedPath = path.join(dir, 'morphed2.jpg'); + gm - .morph([dir + '/morpher.jpg', dir + '/original.png'], dir + '/morphed2.jpg', function morph (err) { + .morph([morpherPath, originalPath], morphedPath, function morph (err) { finish(err); }); } diff --git a/test/morph.js b/test/morph.js index 293e0076..e5bccc59 100644 --- a/test/morph.js +++ b/test/morph.js @@ -1,5 +1,4 @@ - -var assert = require('assert') +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -8,10 +7,10 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - // todo, improve this api to allow multiple images + const morpherPath = path.join(dir, 'morpher.jpg'); + const morphedPath = path.join(dir, 'morphed.jpg'); - gm - .morph(dir + '/morpher.jpg', dir + '/morphed.jpg', function morph (err) { + gm.morph(morpherPath, morphedPath, function morph (err) { finish(err); }); } diff --git a/test/negative.js b/test/negative.js index eef2c3b4..1de124fb 100644 --- a/test/negative.js +++ b/test/negative.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -16,8 +16,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/negative.png', function negative (err) { + const destPath = path.join(dir, 'negative.png'); + m.write(destPath, function negative (err) { finish(err); }); } diff --git a/test/new.js b/test/new.js index b0cbedd5..1f4dd1e1 100644 --- a/test/new.js +++ b/test/new.js @@ -1,9 +1,10 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { var m = gm(525, 110, "#00ff55aa") + .options({imageMagick}) .fontSize(68) .stroke("#efe", 2) .fill("#555") @@ -37,8 +38,8 @@ module.exports = function (_, dir, finish, gm) { if (!gm.integration) return finish(); - m - .write(dir + '/new.png', function New (err){ + const destPath = path.join(dir, 'new.png'); + m.write(destPath, function New (err){ finish(err); }); } diff --git a/test/newImage.js b/test/newImage.js index 80d8f955..89e26a71 100644 --- a/test/newImage.js +++ b/test/newImage.js @@ -1,19 +1,21 @@ // https://github.com/aheckmann/gm/issues/127 -var assert = require('assert') -var fs = require('fs') +const path = require('path'); +const fs = require('fs') -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - createImage().write(dir + '/ignore.me.png', function (err) { + const dest1Path = path.join(dir, 'ignore.me.png'); + createImage().write(dest1Path, function (err) { if (err) return finish(err); createImage().stream(function (err, stdout) { if (err) return finish(err); - stdout.pipe(fs.createWriteStream(dir + '/ignore.me.2.png')) + const dest2Path = path.join(dir, 'ignore.me.2.png'); + stdout.pipe(fs.createWriteStream(dest2Path)) stdout.on('error', finish) stdout.on('end', finish) @@ -22,6 +24,7 @@ module.exports = function (_, dir, finish, gm) { function createImage() { return gm(70, 30, '#000') + .options({imageMagick}) .font("arial", 20) .stroke("#fff", 2) .fill("#888") diff --git a/test/noise1.js b/test/noise1.js index e302678a..9ed9dedc 100644 --- a/test/noise1.js +++ b/test/noise1.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/noise1.png', function noise1 (err) { + const destPath = path.join(dir, 'noise1.png'); + m.write(destPath, function noise1 (err) { finish(err); }); } diff --git a/test/noise2.js b/test/noise2.js index 039c509c..68817248 100644 --- a/test/noise2.js +++ b/test/noise2.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,9 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/noise2.png', function noise2 (err) { + + const destPath = path.join(dir, 'noise2.png'); + m.write(destPath, function noise2 (err) { finish(err); }); } diff --git a/test/options.js b/test/options.js index aaa8bd80..21bec8a1 100644 --- a/test/options.js +++ b/test/options.js @@ -1,8 +1,22 @@ +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); -var assert = require('assert') - , fs = require('fs') +const checkCmd = (cmd, imageMagick) => { + switch (imageMagick) { + case true: + assert.ok(/^convert /.test(cmd)); + break; + case '7+': + assert.ok(/^magick "convert" /.test(cmd)); + break; + default: + assert.ok(/^gm "convert" /.test(cmd)); + break; + } +} -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { var sub = gm.subClass({ subclassed: true }); var s = sub('test').options({ setWithMethod: 2 }); @@ -20,36 +34,41 @@ module.exports = function (_, dir, finish, gm) { assert.equal(true, s2._options.subclassed); assert.equal(undefined, s2._options.setWithMethod); - var writeFile = dir + '/IM-negative' + Math.random() + '.png'; - var imageMagick = gm.subClass({ imageMagick: true }); - if (!gm.integration) return finish(); - imageMagick(dir + '/photo.JPG') + // test commands + // test with subclass + + const photoPath = path.join(dir, 'photo.JPG'); + const writeFile = path.join(dir, `options${Math.random()}.png`); + const instance = gm.subClass({ imageMagick }); + + instance(photoPath) .negative() .write(writeFile, function (err, _1, _2, cmd) { if (err) return finish(err); - assert.ok(/^convert /.test(cmd)); + checkCmd(cmd, imageMagick); fs.stat(writeFile, function (err) { - if (err) return finish(new Error('imagemagick did not write file')); + if (err) return finish(new Error('did not write file')); + try { fs.unlinkSync(writeFile); } catch (e) {} /// inline options - gm(dir + '/photo.JPG') + gm(photoPath) .negative() - .options({ imageMagick: true }) + .options({ imageMagick }) .write(writeFile, function (err, _1, _2, cmd) { if (err) return finish(err); - assert.ok(/^convert /.test(cmd)); + checkCmd(cmd, imageMagick); fs.stat(writeFile, function (err) { - if (err) return finish(new Error('imagemagick did not write file')); + if (err) return finish(new Error('did not write 2nd file')); try { fs.unlinkSync(writeFile); } catch (e) {} diff --git a/test/paint.js b/test/paint.js index 227b967d..075747e0 100644 --- a/test/paint.js +++ b/test/paint.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/paint.png', function paint (err) { + const destPath = path.join(dir, 'paint.png'); + m.write(destPath, function paint (err) { finish(err); }); } diff --git a/test/polygon.js b/test/polygon.js index 8d56628c..2a7c714b 100644 --- a/test/polygon.js +++ b/test/polygon.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -29,8 +29,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/polygon.png', function polygon (err) { + const destPath = path.join(dir, 'polygon.png'); + m.write(destPath, function polygon (err) { finish(err); }); } diff --git a/test/polyline.js b/test/polyline.js index 91dadae7..487a5451 100644 --- a/test/polyline.js +++ b/test/polyline.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -29,8 +29,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/polyline.png', function polyline (err) { + const destPath = path.join(dir, 'polyline.png'); + m.write(destPath, function polyline (err) { finish(err); }); } diff --git a/test/quality.js b/test/quality.js index b7bc6183..f0f5785a 100644 --- a/test/quality.js +++ b/test/quality.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/quality.png', function quality (err) { + const destPath = path.join(dir, 'quality.png'); + m.write(destPath, function quality (err) { finish(err); }); } diff --git a/test/raise.js b/test/raise.js index e154f432..4d630e12 100644 --- a/test/raise.js +++ b/test/raise.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/raise.png', function raise (err) { + const destPath = path.join(dir, 'raise.png'); + m.write(destPath, function raise (err) { finish(err); }); } diff --git a/test/rectangle.js b/test/rectangle.js index da927e89..00e5b6c2 100644 --- a/test/rectangle.js +++ b/test/rectangle.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -32,8 +32,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/rectangle.png', function rectangle (err) { + const destPath = path.join(dir, 'rectangle.png'); + m.write(destPath, function rectangle (err) { finish(err); }); } diff --git a/test/region.js b/test/region.js index 7c62e3ee..07fa6a20 100644 --- a/test/region.js +++ b/test/region.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/region.png', function region (err) { + const destPath = path.join(dir, 'region.png'); + m.write(destPath, function region (err) { finish(err); }); } diff --git a/test/repagePlus.js b/test/repagePlus.js index a7376ba3..14c63010 100644 --- a/test/repagePlus.js +++ b/test/repagePlus.js @@ -1,9 +1,7 @@ -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); -module.exports = function (gm, dir, finish, GM, im) { - - // GraphicsMagick 1.3.12 using on Travis server does not support "repage+" (>=1.3.16 is needed) - if (require('os').platform() === 'linux' && !im) return finish() +module.exports = function (gm, dir, finish, GM) { var m = gm .repage('+'); @@ -15,8 +13,8 @@ module.exports = function (gm, dir, finish, GM, im) { if (!GM.integration) return finish(); - m - .write(dir + '/repage.png', function blur (err) { + const destPath = path.join(dir, 'repage.png'); + m.write(destPath, function blur (err) { finish(err); }); } diff --git a/test/resample.js b/test/resample.js index f048c2fd..688a12fe 100644 --- a/test/resample.js +++ b/test/resample.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/resample.png', function resample (err) { + const destPath = path.join(dir, 'resample.png'); + m.write(destPath, function resample (err) { finish(err); }); } diff --git a/test/resize.js b/test/resize.js index 7c6b6957..af756cc4 100644 --- a/test/resize.js +++ b/test/resize.js @@ -1,47 +1,45 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') +module.exports = function (gm, dir, finish, GM, imageMagick) { -module.exports = function (gm, dir, finish, GM) { - - var a = GM('img.png').resize(10); + var a = GM('img.png').options({imageMagick}).resize(10); var args = a.args(); assert.equal('convert', args[0]); assert.equal('-resize', args[2]); - if (a._options.imageMagick) { + if (imageMagick) { assert.equal('10', args[3]); } else { assert.equal('10x', args[3]); } - var a = GM('img.png').resize(10, 20); + var a = GM('img.png').options({imageMagick}).resize(10, 20); var args = a.args(); assert.equal('convert', args[0]); assert.equal('-resize', args[2]); assert.equal('10x20', args[3]); - var a = GM('img.png').resize(10, false, '%'); + var a = GM('img.png').options({imageMagick}).resize(10, false, '%'); var args = a.args(); assert.equal('convert', args[0]); assert.equal('-resize', args[2]); - if (a._options.imageMagick) { + if (imageMagick) { assert.equal('10%', args[3]); } else { assert.equal('10x%', args[3]); } - var a = GM('img.png').resize('10%'); + var a = GM('img.png').options({imageMagick}).resize('10%'); var args = a.args(); assert.equal('convert', args[0]); assert.equal('-resize', args[2]); - if (a._options.imageMagick) { + if (imageMagick) { assert.equal('10%', args[3]); } else { assert.equal('10%x', args[3]); } - var m = gm - .resize(58, 50, '%'); - + var m = gm.options({imageMagick}).resize(58, 50, '%'); var args= m.args(); assert.equal('convert', args[0]); assert.equal('-resize', args[2]); @@ -50,8 +48,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/resize.png', function resize (err) { + const destPath = path.join(dir, 'resize.png'); + m.write(destPath, function resize (err) { finish(err); }); } diff --git a/test/resizeAndAutoOrientFromBuffer.js b/test/resizeAndAutoOrientFromBuffer.js index 522bdf98..c388d12d 100755 --- a/test/resizeAndAutoOrientFromBuffer.js +++ b/test/resizeAndAutoOrientFromBuffer.js @@ -1,38 +1,36 @@ -var assert = require('assert') -var fs = require('fs') +const assert = require('assert'); +const path = require('path'); +const fs = require('fs') -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { - var original = dir + '/orientation/Portrait_7.jpg'; - var result = dir + '/resizeAutoOrientFromBuffer.png'; + const original = path.join(dir, 'orientation', 'Portrait_7.jpg'); + const result = path.join(dir, 'resizeAutoOrientFromBuffer.png'); var buf = fs.readFileSync(original); var m = gm(buf, 'resizefrombuffer.jpg') + .options({imageMagick}) .autoOrient() .resize('20%') - var args = m.args(); - assert.equal('convert', args[0]); - assert.equal('-', args[1]); - assert.equal('-resize', args[2]); - if (m._options.imageMagick) { - assert.equal('20%', args[3]); - } else { - assert.equal('20%x', args[3]); - } + const expectedArgs = imageMagick ? + ['convert', '-', '-auto-orient', '-resize', '20%', '-'] : + ['convert', '-', '-resize', '20%x', '-']; + + assert.deepEqual(m.args(), expectedArgs); if (!gm.integration) return finish(); - size(original, function (err, origSize) { + size(original, imageMagick, function (err, origSize) { if (err) return finish(err); m .write(result, function resizeFromBuffer (err) { if (err) return finish(err); - size(result, function (err, newSize) { + size(result, imageMagick, function (err, newSize) { if (err) return finish(err); assert.ok(origSize.width / 2 >= newSize.width); assert.ok(origSize.height / 2 >= newSize.height); @@ -42,8 +40,8 @@ module.exports = function (_, dir, finish, gm) { }); - function size (file, cb) { - gm(file).identify(function (err, data) { + function size (file, imageMagick, cb) { + gm(file).options({imageMagick}).identify(function (err, data) { if (err) return cb(err); cb(err, data.size); }); diff --git a/test/resizeBuffer.js b/test/resizeBuffer.js index 208e91a5..e021dafb 100755 --- a/test/resizeBuffer.js +++ b/test/resizeBuffer.js @@ -1,14 +1,16 @@ -var assert = require('assert') -var fs = require('fs') +const assert = require('assert'); +const path = require('path'); +const fs = require('fs') -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { - var original = dir + '/original.jpg'; - var result = dir + '/resizeFromBuffer.png'; + var original = path.join(dir, 'original.jpg'); + var result = path.join(dir, 'resizeFromBuffer.png'); var buf = fs.readFileSync(original); var m = gm(buf, 'resizefrombuffer.jpg') + .options({imageMagick}) .resize('48%') var args = m.args(); @@ -24,14 +26,14 @@ module.exports = function (_, dir, finish, gm) { if (!gm.integration) return finish(); - size(original, function (err, origSize) { + size(original, imageMagick, function (err, origSize) { if (err) return finish(err); m .write(result, function resizeFromBuffer (err) { if (err) return finish(err); - size(result, function (err, newSize) { + size(result, imageMagick, function (err, newSize) { if (err) return finish(err); assert.ok(origSize.width / 2 >= newSize.width); assert.ok(origSize.height / 2 >= newSize.height); @@ -41,8 +43,8 @@ module.exports = function (_, dir, finish, gm) { }); - function size (file, cb) { - gm(file).identify(function (err, data) { + function size (file, imageMagick, cb) { + gm(file).options({imageMagick}).identify(function (err, data) { if (err) return cb(err); cb(err, data.size); }); diff --git a/test/resizeWrong.js b/test/resizeWrong.js index dcf71124..d51abb4c 100644 --- a/test/resizeWrong.js +++ b/test/resizeWrong.js @@ -1,12 +1,11 @@ -var assert = require('assert') -var fs = require('fs') +const path = require('path'); -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - var original = dir + '/original.png'; - var resized = dir + '/resize'; + const original = path.join(dir, 'original.png'); + const resized = path.join(dir, 'resize'); var widths = [300, 700, 400, 800, 200], i, cb; var resizeExact = function (width, index) { var name = resized + index + '.png'; @@ -17,11 +16,12 @@ module.exports = function (_, dir, finish, gm) { index++; } gm(original) + .options({imageMagick}) .resizeExact(width) .write(name, function(err){ if (err) return finish(err); - gm(name) + gm(name).options({imageMagick}) .size(function (err, size) { if (err) return finish(err); if (size.width !== width) { diff --git a/test/roll.js b/test/roll.js index 2c246339..1554841a 100644 --- a/test/roll.js +++ b/test/roll.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/roll.png', function roll (err) { + const destPath = path.join(dir, 'roll.png'); + m.write(destPath, function roll (err) { finish(err); }); } diff --git a/test/rotate.js b/test/rotate.js index 42747b85..28bd2cb1 100644 --- a/test/rotate.js +++ b/test/rotate.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -16,13 +16,13 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/rotate.png', function rotate (err, _0, _1, cmd) { + const destPath = path.join(dir, 'rotate.png'); + m.write(destPath, function rotate (err, _0, _1, cmd) { assert.ok(/"-rotate" "-40"/.test(cmd)); m .rotate('red', 0) - .write(dir + '/rotate.png', function rotate (err, _0, _1, cmd) { + .write(destPath, function rotate (err, _0, _1, cmd) { assert.ok(!/"-rotate" "-40"/.test(cmd)); assert.ok(/"-rotate" "0"/.test(cmd)); finish(err); diff --git a/test/scale.js b/test/scale.js index 09b542e2..0df5151a 100644 --- a/test/scale.js +++ b/test/scale.js @@ -1,9 +1,9 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') +module.exports = function (gm, dir, finish, GM, imageMagick) { -module.exports = function (gm, dir, finish, GM) { - - var a = GM('img.png').scale(100); + var a = GM('img.png').options({imageMagick}).scale(100); var args = a.args(); assert.equal('convert', args[0]); assert.equal('-scale', args[2]); @@ -13,21 +13,19 @@ module.exports = function (gm, dir, finish, GM) { assert.equal('100x', args[3]); } - var a = GM('img.png').scale(100, 200, '%'); + var a = GM('img.png').options({imageMagick}).scale(100, 200, '%'); var args = a.args(); assert.equal('convert', args[0]); assert.equal('-scale', args[2]); assert.equal('100x200%', args[3]); - var a = GM('img.png').scale(100, '200%'); + var a = GM('img.png').options({imageMagick}).scale(100, '200%'); var args = a.args(); assert.equal('convert', args[0]); assert.equal('-scale', args[2]); assert.equal('100x200%', args[3]); - var m = gm - .scale(100, 100); - + var m = gm.options({imageMagick}).scale(100, 100); var args = m.args(); assert.equal('convert', args[0]); assert.equal('-scale', args[2]); @@ -36,8 +34,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/scale.png', function scale (err) { + const destPath = path.join(dir, 'scale.png'); + m.write(destPath, function scale (err) { finish(err); }); } diff --git a/test/selectFrame.js b/test/selectFrame.js index 0626bb6d..0d65b7c0 100644 --- a/test/selectFrame.js +++ b/test/selectFrame.js @@ -1,13 +1,14 @@ -var assert = require('assert'); -var fs = require('fs') +const assert = require('assert'); +const path = require('path'); -module.exports = function (_, dir, finish, gm) { - var m = gm(dir + '/original.gif[0]') +module.exports = function (_, dir, finish, gm, imageMagick) { + const gifPath = path.join(dir, 'original.gif[0]'); + var m = gm(gifPath); if (!gm.integration) return finish(); - m.identify('%#', function (err, hash1) { + m.options({imageMagick}).identify('%#', function (err, hash1) { if (err) return finish(err); m.selectFrame(2).identify('%#', function (err, hash2) { diff --git a/test/sepia.js b/test/sepia.js index 12188f90..3c527a28 100644 --- a/test/sepia.js +++ b/test/sepia.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -16,8 +16,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/sepia.png', function sepia (err) { + const destPath = path.join(dir, 'sepia.png'); + m.write(destPath, function sepia (err) { finish(err); }); } diff --git a/test/setFormat.js b/test/setFormat.js index 221fa412..bd465ef0 100644 --- a/test/setFormat.js +++ b/test/setFormat.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -11,8 +11,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/setformat', function setformat (err) { + const destPath = path.join(dir, 'setFormat.png'); + m.write(destPath, function setformat (err) { finish(err); }); } diff --git a/test/sharpen.js b/test/sharpen.js index e6e53a70..bedc1436 100644 --- a/test/sharpen.js +++ b/test/sharpen.js @@ -1,5 +1,5 @@ - -var assert =require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/sharpen.png', function sharpen (err) { + const destPath = path.join(dir, 'sharpen.png'); + m.write(destPath, function sharpen (err) { finish(err); }); } diff --git a/test/solarize.js b/test/solarize.js index a52cc814..10fd0422 100644 --- a/test/solarize.js +++ b/test/solarize.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/solarize.png', function solarize (err) { + const destPath = path.join(dir, 'solarize.png'); + m.write(destPath, function solarize (err) { finish(err); }); } diff --git a/test/spread.js b/test/spread.js index 127003f6..e1ca3a1d 100644 --- a/test/spread.js +++ b/test/spread.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/spread.png', function spread (err) { + const destPath = path.join(dir, 'spread.png'); + m.write(destPath, function spread (err) { finish(err); }); } diff --git a/test/streamIn.js b/test/streamIn.js index 7a51f6d3..003565de 100644 --- a/test/streamIn.js +++ b/test/streamIn.js @@ -1,11 +1,12 @@ +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); -var assert = require('assert') -var fs = require('fs'); +module.exports = function (_, dir, finish, gm, imageMagick) { -module.exports = function (_, dir, finish, gm) { - - var stream = fs.createReadStream(dir + '/original.jpg'); - var m = gm(stream, "original.jpg"); + const originalPath = path.join(dir, 'original.jpg'); + const stream = fs.createReadStream(originalPath); + const m = gm(stream, "original.jpg").options({imageMagick}); assert.equal(stream, m.sourceStream); assert.equal('original.jpg', m.source); @@ -13,8 +14,8 @@ module.exports = function (_, dir, finish, gm) { if (!gm.integration) return finish(); - m - .write(dir + '/streamIn.png', function streamIn (err) { + const destPath = path.join(dir, 'streamIn.png'); + m.write(destPath, function streamIn (err) { finish(err); }); } diff --git a/test/streamInGetter.js b/test/streamInGetter.js index 9fed5f99..08c2ea89 100644 --- a/test/streamInGetter.js +++ b/test/streamInGetter.js @@ -1,14 +1,16 @@ +const path = require('path'); +const fs = require('fs'); -var assert = require('assert') -var fs = require('fs'); - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - gm(fs.createReadStream(dir + '/original.jpg')) + const originalPath = path.join(dir, 'original.jpg'); + gm(fs.createReadStream(originalPath)) + .options({imageMagick}) .size({bufferStream: true}, function (err, size) { - this.write(dir + '/streamInGetter.png', function streamInGetter (err){ + const destPath = path.join(dir, 'streamInGetter.png'); + this.write(destPath, function streamInGetter (err){ finish(err); }); }); diff --git a/test/streamInOut.js b/test/streamInOut.js index aea32a2d..af33fbeb 100644 --- a/test/streamInOut.js +++ b/test/streamInOut.js @@ -1,15 +1,18 @@ +const path = require('path'); +const fs = require('fs'); -var fs = require('fs'); - -module.exports = function (_, dir, finish, gm) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish(); - gm(fs.createReadStream(dir + '/original.jpg'), "original.jpg") + const originalPath = path.join(dir, 'original.jpg'); + gm(fs.createReadStream(originalPath), "original.jpg") + .options({imageMagick}) .stream(function streamOut (err, stdout, stderr) { if (err) return finish(err); - stdout.pipe(fs.createWriteStream(dir + '/streamInOut.jpg')); + const destPath = path.join(dir, 'streamInOut.jpg'); + stdout.pipe(fs.createWriteStream(destPath)); stdout.on('error', finish); stdout.on('close', finish); }); diff --git a/test/streamOut.js b/test/streamOut.js index 3b070db2..222787cf 100644 --- a/test/streamOut.js +++ b/test/streamOut.js @@ -1,5 +1,5 @@ - -var fs = require('fs'); +const path = require('path'); +const fs = require('fs'); module.exports = function (gm, dir, finish, GM) { @@ -16,7 +16,8 @@ module.exports = function (gm, dir, finish, GM) { gm .stream(function streamOut (err, stdout, stderr) { if (err) return done(err); - stdout.pipe(fs.createWriteStream(dir + '/streamOut.png')); + const destPath = path.join(dir, 'streamOut.png'); + stdout.pipe(fs.createWriteStream(destPath)); stdout.on('error', done); stdout.on('close', done); }); @@ -25,7 +26,8 @@ module.exports = function (gm, dir, finish, GM) { function withoutCallback(done) { var stream = gm.stream() stream.on('error', done) - stream.pipe(fs.createWriteStream(dir + '/streamOut2.png')) + const destPath = path.join(dir, 'streamOut2.png'); + stream.pipe(fs.createWriteStream(destPath)) stream.on('end', done) } } diff --git a/test/streamOutFormat.js b/test/streamOutFormat.js index 4924d265..3f50586d 100644 --- a/test/streamOutFormat.js +++ b/test/streamOutFormat.js @@ -1,18 +1,8 @@ +const assert = require('assert') +const path = require('path'); +const fs = require('fs'); -var assert = require('assert') -var fs = require('fs'); - -module.exports = function (gm, dir, finish, GM) { - /* - assert.throws(function () { - gm.stream() - }, /expects a callback/); - - assert.throws(function () { - gm.stream('PNG') - }, /expects a callback/); - */ - +module.exports = function (gm, dir, finish, GM, imageMagick) { if (!GM.integration) return finish(); @@ -30,7 +20,8 @@ module.exports = function (gm, dir, finish, GM) { gm .stream('PNG', function streamOut (err, stdout, stderr) { if (err) return done(err); - stdout.pipe(fs.createWriteStream(dir + '/streamOut.png')); + const destPath = path.join(dir, 'streamOutFormat.png'); + stdout.pipe(fs.createWriteStream(destPath)); stdout.on('error', done); stdout.on('close', done); }); @@ -39,14 +30,15 @@ module.exports = function (gm, dir, finish, GM) { function withoutCallback(done) { var stream = gm.stream('PNG') stream.on('error', done) - stream.pipe(fs.createWriteStream(dir + '/streamOut2.png')) + const destPath = path.join(dir, 'streamOutFormat2.png'); + stream.pipe(fs.createWriteStream(destPath)) stream.on('end', done) } function checkOutputFormat(done) { var stream = gm.stream('PNG') stream.on('error', done) - GM(stream).format(function (err, value) { + GM(stream).options({imageMagick}).format(function (err, value) { if (err) return done(err) diff --git a/test/streamerr.js b/test/streamerr.js deleted file mode 100644 index d9f6c23d..00000000 --- a/test/streamerr.js +++ /dev/null @@ -1,20 +0,0 @@ -var assert = require('assert') - -module.exports = function (_, dir, finish, gm) { - var svg_file; - svg_file = new Buffer('', 'ascii'); - - // The following invocation should fail, because 'convert' - // has no way of interpreting the file. - gm( - svg_file, - './test.svg' // fiction - ).options({ - imageMagick: true - }).setFormat('png').toBuffer(function(err, buffer) { - assert.ok(err, "Expecting error on this buffer"); - }); - - return finish(); - -} diff --git a/test/strip.js b/test/strip.js index d08cfe8b..b4d3b700 100644 --- a/test/strip.js +++ b/test/strip.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -15,8 +15,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/edge.png', function edge (err) { + const destPath = path.join(dir, 'strip.png'); + m.write(destPath, function strip (err) { finish(err); }); } diff --git a/test/subclass.js b/test/subclass.js index 99018c04..18f3924e 100644 --- a/test/subclass.js +++ b/test/subclass.js @@ -1,8 +1,7 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') - -module.exports = function (_, dir, finish, gm) { - +module.exports = function (_, dir, finish, gm, imageMagick) { assert.equal('gm', gm('test').constructor.name); assert.equal(undefined, gm.prototype._options.imageMagick); @@ -18,11 +17,17 @@ module.exports = function (_, dir, finish, gm) { var g = gm('test'); assert.equal(undefined, g._options.imageMagick); + var imageMagick7 = gm.subClass({ imageMagick: '7+'}); + assert.equal('7+', imageMagick7.prototype._options.imageMagick); + if (!gm.integration) return finish(); - gm(dir + '/photo.JPG') - .thumb(50, 80, dir + '/SUBthumb.png', function subthumb (err) { + const sourcePath = path.join(dir, 'photo.JPG'); + const destPath = path.join(dir, 'subclass.png'); + const m = gm.subClass({ imageMagick }); + m(sourcePath) + .thumb(50, 80, destPath, function subthumb (err) { if (err) return finish(err); finish(); }); diff --git a/test/swirl.js b/test/swirl.js index d12d917f..51f1b0c8 100644 --- a/test/swirl.js +++ b/test/swirl.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/swirl.png', function swirl (err) { + const destPath = path.join(dir, 'swirl.png'); + m.write(destPath, function swirl (err) { finish(err); }); } diff --git a/test/text.js b/test/text.js index 8e9314ca..8e680cc6 100644 --- a/test/text.js +++ b/test/text.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -32,8 +32,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/text.png', function text (err) { + const destPath = path.join(dir, 'text.png'); + m.write(destPath, function text (err) { finish(err); }); } diff --git a/test/thumb.js b/test/thumb.js index 071b3217..e180a844 100644 --- a/test/thumb.js +++ b/test/thumb.js @@ -1,13 +1,13 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - gm - .thumb(150, 40, dir + '/thumb.png', function thumb (err) { + const destPath = path.join(dir, 'thumb.png'); + gm.thumb(150, 40, destPath, function thumb (err) { finish(err); }); } diff --git a/test/thumbnail.js b/test/thumbnail.js index cb9da86c..28054054 100644 --- a/test/thumbnail.js +++ b/test/thumbnail.js @@ -1,5 +1,5 @@ - -var assert = require('assert') +const assert = require('assert'); +const path = require('path'); module.exports = function (gm, dir, finish, GM) { @@ -14,8 +14,8 @@ module.exports = function (gm, dir, finish, GM) { if (!GM.integration) return finish(); - m - .write(dir + '/thumbnail.png', function thumbnail (err) { + const destPath = path.join(dir, 'thumbnail.png'); + m.write(destPath, function thumbnail (err) { finish(err); }); } diff --git a/test/timeout.js b/test/timeout.js index a7e6e762..3e0792f7 100644 --- a/test/timeout.js +++ b/test/timeout.js @@ -1,7 +1,7 @@ +const assert = require('assert'); +const path = require('path'); -var assert = require('assert') - -module.exports = function (img, dir, finish, gm) { +module.exports = function (img, dir, finish, gm, imageMagick) { assert.equal(undefined, gm.prototype._options.timeout); assert.equal(undefined, img._options.timeout); @@ -16,16 +16,18 @@ module.exports = function (img, dir, finish, gm) { if (!gm.integration) return finish(); - gm(dir + '/photo.JPG').options({ timeout: 1 }) - .thumb(50, 80, dir + '/timeout.png', function subthumb (err) { + const sourcePath = path.join(dir, 'photo.JPG'); + const timeoutPath = path.join(dir, 'timeout.png'); + gm(sourcePath).options({ timeout: 1, imageMagick }) + .thumb(50, 80, timeoutPath, function subthumb (err) { assert.ok(err, "Expecting a timeout error"); noTimeout(); }); function noTimeout() { - gm(dir + '/photo.JPG').options({ timeout: 0 }) - .thumb(50, 80, dir + '/timeout.png', function subthumb (err) { + gm(sourcePath).options({ timeout: 0, imageMagick }) + .thumb(50, 80, timeoutPath, function subthumb (err) { finish(err); }); } diff --git a/test/webp.js b/test/webp.js index 65890a1d..0279fbea 100644 --- a/test/webp.js +++ b/test/webp.js @@ -1,20 +1,21 @@ -var assert = require('assert') -var fs = require('fs') +const assert = require('assert'); +const path = require('path'); +const fs = require('fs') -module.exports = function (_, dir, finish, gm, im) { +module.exports = function (_, dir, finish, gm, imageMagick) { if (!gm.integration) return finish() // Don't know how to install IM with WEBP on ubuntu - if (require('os').platform() === 'linux') return finish() + // if (require('os').platform() === 'linux') return finish() // GraphicsMagick currently does not support webp :( - if (!im) return finish() + // if (!im) return finish() gm = gm.subClass({ - imageMagick: true + imageMagick }) - var image = dir + '/original.png' + const imagePath = path.join(dir, 'original.png'); write(function (err) { if (err) return finish(err) @@ -23,11 +24,12 @@ module.exports = function (_, dir, finish, gm, im) { }) function write(done) { - gm(image) - .write(dir + '/original.x.webp', function (err) { + const webpPath = path.join(dir, 'original.x.webp'); + gm(imagePath) + .write(webpPath, function (err) { if (err) return done(err) - gm(dir + '/original.x.webp').identify(function (err, value) { + gm(webpPath).identify(function (err, value) { if (err) return done(err) assert.ok(value) @@ -38,7 +40,7 @@ module.exports = function (_, dir, finish, gm, im) { } function stream(done) { - gm(image) + gm(imagePath) .stream('webp', function (err, stdout) { if (err) return done(err)