diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-11 11:52:34 +0100 |
commit | 88108880bbdba473cfe36ecbebc1c3c4f972e102 (patch) | |
tree | b242efb3b4f0d7e49d88f2d1f2063b5b3b0489c0 /server/helpers/image-utils.ts | |
parent | 53a94c7cfa8368da4cd248d65df8346905938f0c (diff) | |
parent | 9b712a2017e4ab3cf12cd6bd58278905520159d0 (diff) | |
download | PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.gz PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.tar.zst PeerTube-88108880bbdba473cfe36ecbebc1c3c4f972e102.zip |
Merge branch 'develop' into pr/1217
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r-- | server/helpers/image-utils.ts | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index 3eaa674ed..e43ea3f1d 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -1,13 +1,26 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import * as sharp from 'sharp' | 2 | import * as sharp from 'sharp' |
3 | import { remove } from 'fs-extra' | 3 | import { readFile, remove } from 'fs-extra' |
4 | import { logger } from './logger' | ||
4 | 5 | ||
5 | async function processImage ( | 6 | async function processImage ( |
6 | physicalFile: { path: string }, | 7 | physicalFile: { path: string }, |
7 | destination: string, | 8 | destination: string, |
8 | newSize: { width: number, height: number } | 9 | newSize: { width: number, height: number } |
9 | ) { | 10 | ) { |
10 | await sharp(physicalFile.path) | 11 | if (physicalFile.path === destination) { |
12 | throw new Error('Sharp needs an input path different that the output path.') | ||
13 | } | ||
14 | |||
15 | logger.debug('Processing image %s to %s.', physicalFile.path, destination) | ||
16 | |||
17 | // Avoid sharp cache | ||
18 | const buf = await readFile(physicalFile.path) | ||
19 | const sharpInstance = sharp(buf) | ||
20 | |||
21 | await remove(destination) | ||
22 | |||
23 | await sharpInstance | ||
11 | .resize(newSize.width, newSize.height) | 24 | .resize(newSize.width, newSize.height) |
12 | .toFile(destination) | 25 | .toFile(destination) |
13 | 26 | ||