Remove gm dependency and update tests.
This commit is contained in:
parent
b1ceba7664
commit
75a46212da
8 changed files with 61 additions and 37 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue