Remove gm dependency and update tests.
This commit is contained in:
parent
b1ceba7664
commit
75a46212da
8 changed files with 61 additions and 37 deletions
|
@ -10,7 +10,7 @@ test:
|
||||||
stage: test
|
stage: test
|
||||||
before_script:
|
before_script:
|
||||||
- npm install
|
- npm install
|
||||||
- node test/fixtures/mongo-user.js test/fixtures/mongo-file.js
|
- npm run init
|
||||||
script:
|
script:
|
||||||
- npm test
|
- npm test
|
||||||
tags:
|
tags:
|
||||||
|
@ -25,4 +25,3 @@ cache:
|
||||||
untracked: true
|
untracked: true
|
||||||
paths:
|
paths:
|
||||||
- node_modules
|
- node_modules
|
||||||
- web/public/jspm_packages
|
|
||||||
|
|
16
circle.yml
16
circle.yml
|
@ -1,16 +0,0 @@
|
||||||
machine:
|
|
||||||
node:
|
|
||||||
version: iojs-3.2.0
|
|
||||||
|
|
||||||
test:
|
|
||||||
pre:
|
|
||||||
- mongo hostr test/fixtures/mongo-user.js test/fixtures/mongo-file.js
|
|
||||||
override:
|
|
||||||
- npm run cover
|
|
||||||
|
|
||||||
dependencies:
|
|
||||||
cache_directories:
|
|
||||||
- node_modules
|
|
||||||
- web/public/jspm_packages
|
|
||||||
post:
|
|
||||||
- npm run jspm
|
|
|
@ -1,10 +1,33 @@
|
||||||
import debugname from 'debug';
|
import debugname from 'debug';
|
||||||
const debug = debugname('hostr-api:resize');
|
const debug = debugname('hostr-api:resize');
|
||||||
import gm from 'gm';
|
import lwip from 'lwip';
|
||||||
|
import imageType from 'image-type';
|
||||||
|
|
||||||
|
const supported = ['jpg', 'png', 'gif'];
|
||||||
|
|
||||||
export default function(input, size) {
|
export default function(input, size) {
|
||||||
debug('Resizing');
|
debug('Resizing');
|
||||||
const image = gm(input);
|
|
||||||
|
|
||||||
return image.resize(size.width, size.height, '>').stream();
|
const type = imageType(input);
|
||||||
|
|
||||||
|
if (!type.ext || supported.indexOf(type.ext) < 0) {
|
||||||
|
throw new Error('Not a supported image.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
lwip.open(input, type.ext, (errIn, image) => {
|
||||||
|
if (errIn) {
|
||||||
|
return reject(errIn);
|
||||||
|
}
|
||||||
|
image.cover(size.width, size.height, (errOut, resized) => {
|
||||||
|
if (errOut) {
|
||||||
|
return reject(errOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
resized.toBuffer(type.ext, (errBuf, buffer) => {
|
||||||
|
resolve(buffer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
"init": "node -r babel/register -e \"require('./lib/storage')();\"",
|
"init": "node -r babel/register -e \"require('./lib/storage')();\"",
|
||||||
"jspm": "jspm install",
|
"jspm": "jspm install",
|
||||||
"start": "npm run build && node -r babel/register app.js",
|
"start": "npm run build && node -r babel/register app.js",
|
||||||
"test": "npm run test-seed && mocha -r babel/register test/**/*.spec.js",
|
"test": "npm run test-seed && mocha -r babel/register test/**/*.spec.js && mocha -r babel/register -r co-mocha test/unit/image-resize.spec.js",
|
||||||
"test-seed": "node test/fixtures/mongo-user.js && node test/fixtures/mongo-file.js",
|
"test-seed": "node test/fixtures/mongo-user.js && node test/fixtures/mongo-file.js",
|
||||||
"watch": "parallelshell \"npm run watch-js\" \"npm run watch-sass\" \"npm run watch-server\"",
|
"watch": "parallelshell \"npm run watch-js\" \"npm run watch-sass\" \"npm run watch-server\"",
|
||||||
"watch-js": "babel -Dw -m system -d web/public/build web/public/src",
|
"watch-js": "babel -Dw -m system -d web/public/build web/public/src",
|
||||||
|
@ -34,8 +34,9 @@
|
||||||
"debug": "~2.2.0",
|
"debug": "~2.2.0",
|
||||||
"ejs": "~2.3.2",
|
"ejs": "~2.3.2",
|
||||||
"form-data": "^1.0.0-rc3",
|
"form-data": "^1.0.0-rc3",
|
||||||
"gm": "~1.18.1",
|
|
||||||
"http-errors": "~1.3.1",
|
"http-errors": "~1.3.1",
|
||||||
|
"image-size": "^0.5.0",
|
||||||
|
"image-type": "^2.1.0",
|
||||||
"jspm": "~0.16.0",
|
"jspm": "~0.16.0",
|
||||||
"kcors": "~1.0.1",
|
"kcors": "~1.0.1",
|
||||||
"koa": "~1.0.0",
|
"koa": "~1.0.0",
|
||||||
|
@ -52,6 +53,7 @@
|
||||||
"koa-statsd": "~0.0.2",
|
"koa-statsd": "~0.0.2",
|
||||||
"koa-views": "~3.1.0",
|
"koa-views": "~3.1.0",
|
||||||
"koa-websocket": "~1.1.0",
|
"koa-websocket": "~1.1.0",
|
||||||
|
"lwip": "0.0.9",
|
||||||
"mime-types": "~2.1.5",
|
"mime-types": "~2.1.5",
|
||||||
"moment": "~2.10.6",
|
"moment": "~2.10.6",
|
||||||
"mongodb-promisified": "~1.0.3",
|
"mongodb-promisified": "~1.0.3",
|
||||||
|
@ -69,6 +71,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-eslint": "^4.0.10",
|
"babel-eslint": "^4.0.10",
|
||||||
|
"co-mocha": "^1.1.2",
|
||||||
"eslint": "~1.3.0",
|
"eslint": "~1.3.0",
|
||||||
"eslint-config-airbnb": "0.0.8",
|
"eslint-config-airbnb": "0.0.8",
|
||||||
"istanbul": "~0.3.18",
|
"istanbul": "~0.3.18",
|
||||||
|
|
BIN
test/fixtures/app-icon.png
vendored
Normal file
BIN
test/fixtures/app-icon.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
BIN
test/fixtures/kim.gif
vendored
Normal file
BIN
test/fixtures/kim.gif
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
|
@ -3,14 +3,33 @@ import path from 'path';
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import tmp from 'tmp';
|
import tmp from 'tmp';
|
||||||
import resize from '../../lib/resize';
|
import resize from '../../lib/resize';
|
||||||
|
import imageType from 'image-type';
|
||||||
|
|
||||||
|
describe('Image resizing', () => {
|
||||||
|
it('should resize a jpg', function* resizeImage() {
|
||||||
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'utah-arches.jpg'));
|
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'utah-arches.jpg'));
|
||||||
|
|
||||||
describe('Image resizing', function() {
|
|
||||||
it('should resize an image', function*() {
|
|
||||||
const imageBuffer = yield resize(file, {height: 100, width: 100});
|
const imageBuffer = yield resize(file, {height: 100, width: 100});
|
||||||
const tmpFile = tmp.tmpNameSync();
|
const tmpFile = tmp.tmpNameSync() + '.jpg';
|
||||||
fs.writeFileSync(tmpFile + '.jpg', imageBuffer);
|
fs.writeFileSync(tmpFile, imageBuffer);
|
||||||
assert(tmpFile);
|
const type = imageType(fs.readFileSync(tmpFile));
|
||||||
|
assert(type.ext === 'jpg');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resize a png', function* resizeImage() {
|
||||||
|
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'app-icon.png'));
|
||||||
|
const imageBuffer = yield resize(file, {height: 100, width: 100});
|
||||||
|
const tmpFile = tmp.tmpNameSync() + '.png';
|
||||||
|
fs.writeFileSync(tmpFile, imageBuffer);
|
||||||
|
const type = imageType(fs.readFileSync(tmpFile));
|
||||||
|
assert(type.ext === 'png');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resize a gif', function* resizeImage() {
|
||||||
|
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'kim.gif'));
|
||||||
|
const imageBuffer = yield resize(file, {height: 100, width: 100});
|
||||||
|
const tmpFile = tmp.tmpNameSync() + '.gif';
|
||||||
|
fs.writeFileSync(tmpFile, imageBuffer);
|
||||||
|
const type = imageType(fs.readFileSync(tmpFile));
|
||||||
|
assert(type.ext === 'gif');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import gm from 'gm';
|
import sizeOf from 'image-size';
|
||||||
import { agent } from 'supertest';
|
import { agent } from 'supertest';
|
||||||
import app from '../../app';
|
import app from '../../app';
|
||||||
|
|
||||||
|
@ -46,9 +46,7 @@ describe('hostr-web file', function() {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-type', 'image/jpeg')
|
.expect('Content-type', 'image/jpeg')
|
||||||
.expect(function(response) {
|
.expect(function(response) {
|
||||||
gm(response.body).size((err, size) => {
|
assert(sizeOf(response.body).width === 150);
|
||||||
assert(size.width === 150);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.end(done);
|
.end(done);
|
||||||
});
|
});
|
||||||
|
@ -61,9 +59,7 @@ describe('hostr-web file', function() {
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.expect('Content-type', 'image/jpeg')
|
.expect('Content-type', 'image/jpeg')
|
||||||
.expect(function(response) {
|
.expect(function(response) {
|
||||||
gm(response.body).size((err, size) => {
|
assert(sizeOf(response.body).width === 970);
|
||||||
assert(size.width === 970);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.end(done);
|
.end(done);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue