diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-13 18:17:05 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-14 16:03:09 +0100 |
commit | ac81d1a06d57b9ae86663831e7f5edcef57b0fa4 (patch) | |
tree | da31775c9533d3e270f68f921e146f086bf7c0b8 /server/helpers/image-utils.ts | |
parent | e883399fa6caa56bb8519c9a2e22d88001f26661 (diff) | |
download | PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.gz PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.tar.zst PeerTube-ac81d1a06d57b9ae86663831e7f5edcef57b0fa4.zip |
Add ability to set video thumbnail/preview
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r-- | server/helpers/image-utils.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts new file mode 100644 index 000000000..ba57b5812 --- /dev/null +++ b/server/helpers/image-utils.ts | |||
@@ -0,0 +1,21 @@ | |||
1 | import 'multer' | ||
2 | import * as sharp from 'sharp' | ||
3 | import { unlinkPromise } from './core-utils' | ||
4 | |||
5 | async function processImage ( | ||
6 | physicalFile: Express.Multer.File, | ||
7 | destination: string, | ||
8 | newSize: { width: number, height: number } | ||
9 | ) { | ||
10 | await sharp(physicalFile.path) | ||
11 | .resize(newSize.width, newSize.height) | ||
12 | .toFile(destination) | ||
13 | |||
14 | await unlinkPromise(physicalFile.path) | ||
15 | } | ||
16 | |||
17 | // --------------------------------------------------------------------------- | ||
18 | |||
19 | export { | ||
20 | processImage | ||
21 | } | ||