diff options
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r-- | server/helpers/image-utils.ts | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index e43ea3f1d..bd81aa3ba 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -4,18 +4,19 @@ import { readFile, remove } from 'fs-extra' | |||
4 | import { logger } from './logger' | 4 | import { logger } from './logger' |
5 | 5 | ||
6 | async function processImage ( | 6 | async function processImage ( |
7 | physicalFile: { path: string }, | 7 | path: string, |
8 | destination: string, | 8 | destination: string, |
9 | newSize: { width: number, height: number } | 9 | newSize: { width: number, height: number }, |
10 | keepOriginal = false | ||
10 | ) { | 11 | ) { |
11 | if (physicalFile.path === destination) { | 12 | if (path === destination) { |
12 | throw new Error('Sharp needs an input path different that the output path.') | 13 | throw new Error('Sharp needs an input path different that the output path.') |
13 | } | 14 | } |
14 | 15 | ||
15 | logger.debug('Processing image %s to %s.', physicalFile.path, destination) | 16 | logger.debug('Processing image %s to %s.', path, destination) |
16 | 17 | ||
17 | // Avoid sharp cache | 18 | // Avoid sharp cache |
18 | const buf = await readFile(physicalFile.path) | 19 | const buf = await readFile(path) |
19 | const sharpInstance = sharp(buf) | 20 | const sharpInstance = sharp(buf) |
20 | 21 | ||
21 | await remove(destination) | 22 | await remove(destination) |
@@ -24,7 +25,7 @@ async function processImage ( | |||
24 | .resize(newSize.width, newSize.height) | 25 | .resize(newSize.width, newSize.height) |
25 | .toFile(destination) | 26 | .toFile(destination) |
26 | 27 | ||
27 | await remove(physicalFile.path) | 28 | if (keepOriginal !== true) await remove(path) |
28 | } | 29 | } |
29 | 30 | ||
30 | // --------------------------------------------------------------------------- | 31 | // --------------------------------------------------------------------------- |