サムネイルを予め生成するように

This commit is contained in:
syuilo
2018-05-03 20:03:14 +09:00
parent 75764e59e1
commit 15e4cf1243
9 changed files with 182 additions and 107 deletions

View File

@@ -0,0 +1,25 @@
import * as stream from 'stream';
import * as Gm from 'gm';
import { IDriveFile, getDriveFileBucket } from '../models/drive-file';
const gm = Gm.subClass({
imageMagick: true
});
export default async function(file: IDriveFile): Promise<stream.Readable> {
if (!/^image\/.*$/.test(file.contentType)) return null;
const bucket = await getDriveFileBucket();
const readable = bucket.openDownloadStream(file._id);
const g = gm(readable);
const stream = g
.resize(256, 256)
.compress('jpeg')
.quality(70)
.interlace('line')
.stream();
return stream;
}