diff options
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r-- | server/helpers/image-utils.ts | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index fdf06e848..3ebf07305 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { extname } from 'path' | ||
2 | import { remove, rename } from 'fs-extra' | 1 | import { remove, rename } from 'fs-extra' |
2 | import { extname } from 'path' | ||
3 | import { convertWebPToJPG, processGIF } from './ffmpeg-utils' | 3 | import { convertWebPToJPG, processGIF } from './ffmpeg-utils' |
4 | import { logger } from './logger' | 4 | import { logger } from './logger' |
5 | 5 | ||
@@ -13,17 +13,31 @@ async function processImage ( | |||
13 | ) { | 13 | ) { |
14 | const extension = extname(path) | 14 | const extension = extname(path) |
15 | 15 | ||
16 | if (path === destination) { | ||
17 | throw new Error('Jimp/FFmpeg needs an input path different that the output path.') | ||
18 | } | ||
19 | |||
20 | logger.debug('Processing image %s to %s.', path, destination) | ||
21 | |||
16 | // Use FFmpeg to process GIF | 22 | // Use FFmpeg to process GIF |
17 | if (extension === '.gif') { | 23 | if (extension === '.gif') { |
18 | return processGIF(path, destination, newSize, keepOriginal) | 24 | await processGIF(path, destination, newSize) |
25 | } else { | ||
26 | await jimpProcessor(path, destination, newSize) | ||
19 | } | 27 | } |
20 | 28 | ||
21 | if (path === destination) { | 29 | if (keepOriginal !== true) await remove(path) |
22 | throw new Error('Jimp needs an input path different that the output path.') | 30 | } |
23 | } | ||
24 | 31 | ||
25 | logger.debug('Processing image %s to %s.', path, destination) | 32 | // --------------------------------------------------------------------------- |
26 | 33 | ||
34 | export { | ||
35 | processImage | ||
36 | } | ||
37 | |||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | async function jimpProcessor (path: string, destination: string, newSize: { width: number, height: number }) { | ||
27 | let jimpInstance: any | 41 | let jimpInstance: any |
28 | 42 | ||
29 | try { | 43 | try { |
@@ -44,12 +58,4 @@ async function processImage ( | |||
44 | .resize(newSize.width, newSize.height) | 58 | .resize(newSize.width, newSize.height) |
45 | .quality(80) | 59 | .quality(80) |
46 | .writeAsync(destination) | 60 | .writeAsync(destination) |
47 | |||
48 | if (keepOriginal !== true) await remove(path) | ||
49 | } | ||
50 | |||
51 | // --------------------------------------------------------------------------- | ||
52 | |||
53 | export { | ||
54 | processImage | ||
55 | } | 61 | } |