aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-05-31 20:03:28 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-10 14:01:49 +0200
commite6dfa58689e88633db8304a8541a75edd893c645 (patch)
treeb8a06bf38370328e753940a8c2ae85d6d03413a5 /server
parentb84d4c809f0b1c4b3f2029f56b81dbca37364f36 (diff)
downloadPeerTube-e6dfa58689e88633db8304a8541a75edd893c645.tar.gz
PeerTube-e6dfa58689e88633db8304a8541a75edd893c645.tar.zst
PeerTube-e6dfa58689e88633db8304a8541a75edd893c645.zip
space optimizations for `node_modules` and client stats removal
- replace sharp with lighter jimp alternative - remove stats in builds fixes #2807
Diffstat (limited to 'server')
-rw-r--r--server/helpers/image-utils.ts11
1 files changed, 6 insertions, 5 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts
index bd81aa3ba..b1c7d3d47 100644
--- a/server/helpers/image-utils.ts
+++ b/server/helpers/image-utils.ts
@@ -1,7 +1,7 @@
1import 'multer' 1import 'multer'
2import * as sharp from 'sharp'
3import { readFile, remove } from 'fs-extra' 2import { readFile, remove } from 'fs-extra'
4import { logger } from './logger' 3import { logger } from './logger'
4const Jimp = require('jimp')
5 5
6async function processImage ( 6async function processImage (
7 path: string, 7 path: string,
@@ -10,20 +10,21 @@ async function processImage (
10 keepOriginal = false 10 keepOriginal = false
11) { 11) {
12 if (path === destination) { 12 if (path === destination) {
13 throw new Error('Sharp needs an input path different that the output path.') 13 throw new Error('Jimp needs an input path different that the output path.')
14 } 14 }
15 15
16 logger.debug('Processing image %s to %s.', path, destination) 16 logger.debug('Processing image %s to %s.', path, destination)
17 17
18 // Avoid sharp cache 18 // Avoid sharp cache
19 const buf = await readFile(path) 19 const buf = await readFile(path)
20 const sharpInstance = sharp(buf) 20 const jimpInstance = await Jimp.read(buf)
21 21
22 await remove(destination) 22 await remove(destination)
23 23
24 await sharpInstance 24 await jimpInstance
25 .resize(newSize.width, newSize.height) 25 .resize(newSize.width, newSize.height)
26 .toFile(destination) 26 .quality(80)
27 .writeAsync(destination)
27 28
28 if (keepOriginal !== true) await remove(path) 29 if (keepOriginal !== true) await remove(path)
29} 30}