Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b2ca6ca

Browse files
authored
Merge pull request #846 from aheckmann/windows
Windows
2 parents be71cef + bf11965 commit b2ca6ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+1011
-859
lines changed

.github/workflows/node.js.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,36 @@ on:
1111

1212
jobs:
1313
build:
14+
runs-on: ${{ matrix.os }}
1415

15-
runs-on: ubuntu-latest
16+
env:
17+
DEBUG: "gm*"
1618

1719
strategy:
1820
matrix:
21+
os: [windows-latest, ubuntu-latest]
1922
node-version: [14.x, 16.x, 18.x]
2023
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2124

2225
steps:
23-
- name: Install GraphicsMagic and Imagemagick
26+
- name: Install GraphicsMagic and Imagemagick on Ubuntu
27+
if: contains(matrix.os, 'ubuntu')
2428
run: sudo apt-get install -y imagemagick graphicsmagick
29+
- name: Install GraphicsMagic and Imagemagick on Windows
30+
if: contains(matrix.os, 'windows')
31+
run: choco install -y imagemagick graphicsmagick
2532
- uses: actions/checkout@v3
2633
- name: Use Node.js ${{ matrix.node-version }}
2734
uses: actions/setup-node@v3
2835
with:
2936
node-version: ${{ matrix.node-version }}
3037
- run: npm i
31-
- run: npm test
38+
- name: Run tests on Windows
39+
if: contains(matrix.os, 'windows')
40+
shell: cmd
41+
run: |
42+
call refreshenv
43+
npm test
44+
- name: Run tests on Ubuntu
45+
if: contains(matrix.os, 'ubuntu')
46+
run: npm test

Makefile

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,31 @@ or clone the repo:
2424

2525
## Use ImageMagick instead of gm
2626

27-
Subclass `gm` to enable ImageMagick, optionally specifying the path to the executable.
27+
Subclass `gm` to enable [ImageMagick 7+](https://imagemagick.org/script/porting.php)
28+
29+
```js
30+
const fs = require('fs')
31+
const gm = require('gm').subClass({ imageMagick: '7+' });
32+
```
33+
34+
Or, to enable ImageMagick legacy mode (for ImageMagick version < 7)
35+
36+
```js
37+
const fs = require('fs')
38+
const gm = require('gm').subClass({ imageMagick: true });
39+
```
40+
41+
## Specify the executable path
42+
43+
Optionally specify the path to the executable.
2844

2945
```js
3046
const fs = require('fs')
3147
const gm = require('gm').subClass({
32-
imageMagick: true,
3348
appPath: String.raw`C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe`
3449
});
35-
36-
// resize and remove EXIF profile data
37-
gm('/path/to/my/img.jpg')
38-
.resize(240, 240)
39-
...
4050
```
4151

42-
4352
## Basic Usage
4453

4554
```js
@@ -622,6 +631,15 @@ http://github.com/quiiver/magickal-node
622631
## Plugins
623632
[https://github.com/aheckmann/gm/wiki](https://github.com/aheckmann/gm/wiki)
624633

634+
## Tests
635+
`npm test`
636+
637+
To run a single test:
638+
639+
```
640+
npm test -- alpha.js
641+
```
642+
625643
## License
626644

627645
(The MIT License)

lib/command.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,28 @@ module.exports = function (proto) {
202202

203203
proto._spawn = function _spawn (args, bufferOutput, callback) {
204204
var appPath = this._options.appPath || '';
205-
var bin = this._options.imageMagick
206-
? appPath + args.shift()
207-
: appPath + 'gm'
205+
var bin
206+
207+
// Resolve executable
208+
switch (this._options.imageMagick) {
209+
// legacy behavior
210+
case true:
211+
bin = args.shift();
212+
break;
213+
214+
// ImgeMagick >= 7
215+
case '7+':
216+
bin = 'magick'
217+
break;
218+
219+
// GraphicsMagick
220+
default:
221+
bin = 'gm';
222+
break;
223+
}
224+
225+
// Prepend app path
226+
bin = appPath + bin
208227

209228
var cmd = bin + ' ' + args.map(utils.escape).join(' ')
210229
, self = this

lib/compare.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// compare
22

33
var spawn = require('cross-spawn');
4+
var debug = require('debug')('gm');
5+
var utils = require('./utils');
46

57
/**
68
* Compare two images uses graphicsmagicks `compare` command.
@@ -22,13 +24,28 @@ module.exports = exports = function (proto) {
2224

2325
var isImageMagick = this._options && this._options.imageMagick;
2426
var appPath = this._options && this._options.appPath || '';
25-
var bin = isImageMagick
26-
? appPath + 'compare'
27-
: appPath + 'gm'
28-
var args = ['-metric', 'mse', orig, compareTo]
29-
if (!isImageMagick) {
27+
var args = ['-metric', 'mse', orig, compareTo];
28+
29+
// Resove executable
30+
let bin;
31+
32+
switch (isImageMagick) {
33+
case true:
34+
bin = 'compare';
35+
break;
36+
case '7+':
37+
bin = 'magick'
3038
args.unshift('compare');
39+
break;
40+
default:
41+
bin = 'gm'
42+
args.unshift('compare');
43+
break
3144
}
45+
46+
// Prepend app path
47+
bin = appPath + bin
48+
3249
var tolerance = 0.4;
3350
// outputting the diff image
3451
if (typeof options === 'object') {
@@ -56,13 +73,13 @@ module.exports = exports = function (proto) {
5673
}
5774
args.push(options.file);
5875
}
59-
76+
6077
if (typeof options.tolerance != 'undefined') {
6178
if (typeof options.tolerance !== 'number') {
6279
throw new TypeError('The tolerance value should be a number');
6380
}
6481
tolerance = options.tolerance;
65-
}
82+
}
6683
} else {
6784
// For ImageMagick diff file is required but we don't care about it, so null it out
6885
if (isImageMagick) {
@@ -76,6 +93,9 @@ module.exports = exports = function (proto) {
7693
}
7794
}
7895

96+
var cmd = bin + ' ' + args.map(utils.escape).join(' ')
97+
debug(cmd);
98+
7999
var proc = spawn(bin, args);
80100
var stdout = '';
81101
var stderr = '';

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
],
2929
"main": "./index",
3030
"scripts": {
31-
"test": "make test;"
31+
"security": "npm audit",
32+
"test": "npm run security && npm run test-integration",
33+
"test-integration": "node test/ --integration",
34+
"test-unit": "node test/"
3235
},
3336
"repository": {
3437
"type": "git",
@@ -44,4 +47,4 @@
4447
"cross-spawn": "^4.0.0",
4548
"debug": "^3.1.0"
4649
}
47-
}
50+
}

test/109.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
var assert = require('assert')
2-
var fs = require('fs')
1+
const fs = require('fs');
2+
const path = require('path');
33

4-
module.exports = function (_, dir, finish, gm) {
5-
if (!gm.integration)
6-
return finish();
4+
module.exports = function (_, dir, finish, gm, imageMagick) {
5+
if (!gm.integration) return finish();
76

8-
var original = dir + '/original.jpg';
9-
var result = dir + '/fromBuffer.png';
7+
const original = path.join(dir, 'original.jpg');
8+
const buf = fs.readFileSync(original);
9+
const m = gm(buf, 'original.jpg').options({ imageMagick });
1010

11-
var buf = fs.readFileSync(original);
12-
var m = gm(buf, 'original.jpg');
13-
14-
m.identify(function (err, x) {
11+
m.identify(function (err, _) {
1512
finish(err);
1613
});
1714

test/118.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
/*
2-
* If only the width is specified for a resize operation,
2+
* If only the width is specified for a resize operation,
33
* GraphicsMagick requires the format
44
* -resize 10x
55
* while ImageMagick requires the format
6-
* -resize 10
6+
* -resize 10
77
*
88
*/
9-
var assert = require('assert')
9+
const assert = require('assert')
10+
const path = require('path');
1011

11-
module.exports = function (_, dir, finish, gm) {
12-
if (!gm.integration) return finish();
13-
14-
var src = dir + '/originalSideways.jpg';
15-
var dst = dir + '/originalSideways10x.jpg';
12+
module.exports = function (_, dir, finish, gm, imageMagick) {
13+
if (!gm.integration) return finish();
1614

17-
gm(src).resize(10).write(dst, function(err) {
18-
gm(dst).size(function(err, size) {
15+
var src = path.join(dir, 'originalSideways.jpg');
16+
var dst = path.join(dir, 'originalSideways10x.jpg');
17+
18+
gm(src).options({ imageMagick }).resize(10).write(dst, function(err) {
19+
gm(dst).options({ imageMagick }).size(function(err, size) {
1920
if (err) return finish(err);
2021
assert.equal(10, size.width);
2122
finish();

test/393.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
'use strict';
1+
const assert = require('assert');
2+
const fs = require('fs');
3+
const path = require('path');
24

3-
var assert = require('assert');
4-
var fs = require('fs');
5-
var path = require('path');
6-
7-
module.exports = function (_, dir, finish, gm) {
5+
module.exports = function (_, dir, finish, gm, imageMagick) {
86
if (!gm.integration) return finish();
97

10-
var imagePath = path.join(__dirname, './fixtures/nyancat.gif');
8+
var imagePath = path.join(__dirname, 'fixtures', 'nyancat.gif');
119
var inputStream = fs.createReadStream(imagePath);
12-
gm(inputStream)
13-
.identify({ bufferStream: true }, function(err, value) {
10+
gm(inputStream).options({ imageMagick }).identify({ bufferStream: true }, function(err, value) {
1411
if (err) return finish(err);
1512
var size = value.size;
1613
assert.equal(400, size.width);

test/417.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11

2-
var assert = require('assert')
3-
var fs = require('fs');
4-
var path = require('path');
2+
const assert = require('assert')
3+
const fs = require('fs');
4+
const path = require('path');
55

6-
module.exports = function (_, dir, finish, gm) {
6+
module.exports = function (_, dir, finish, gm, imageMagick) {
77
if (!gm.integration)
88
return finish();
99

10-
gm(dir + '/original.jpg')
11-
.thumb(150, 40, dir + '/thumb.png', function thumb (err) {
12-
gm(dir + '/thumb.png')
13-
.size(function (err, size) {
14-
if (err) return finish(err);
10+
const originalPathName = path.join(dir, 'original.jpg');
11+
const thumbPathName = path.join(dir, 'thumb.png');
1512

16-
assert.equal(142, size.width);
17-
assert.equal(40, size.height);
13+
gm(originalPathName).options({ imageMagick }).thumb(150, 40, thumbPathName, function thumb (err) {
14+
gm(thumbPathName).options({ imageMagick }).size(function (err, size) {
15+
if (err) return finish(err);
1816

19-
gm(dir + '/original.jpg')
20-
.thumbExact(150, 40, dir + '/thumb.png', function thumb (err) {
21-
gm(dir + '/thumb.png')
22-
.size(function (err, size) {
23-
assert.equal(150, size.width);
24-
assert.equal(40, size.height);
25-
finish(err);
26-
});
17+
assert.equal(142, size.width);
18+
assert.equal(40, size.height);
19+
20+
gm(originalPathName).options({ imageMagick }).thumbExact(150, 40, thumbPathName, function thumb (err) {
21+
gm(thumbPathName).options({ imageMagick }).size(function (err, size) {
22+
assert.equal(150, size.width);
23+
assert.equal(40, size.height);
24+
finish(err);
2725
});
2826
});
27+
});
2928
});
3029
}

0 commit comments

Comments
 (0)