Remove gm dependency and update tests.

This commit is contained in:
Jonathan Cremin 2016-05-24 21:33:09 +01:00
parent b1ceba7664
commit 75a46212da
8 changed files with 61 additions and 37 deletions

View file

@ -1,10 +1,33 @@
import debugname from 'debug';
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) {
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);
});
});
});
});
}