サムネイルを予め生成するように
This commit is contained in:
25
src/drive/gen-thumbnail.ts
Normal file
25
src/drive/gen-thumbnail.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user