aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/image-utils.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-12-04 15:12:54 +0100
committerChocobozzz <me@florianbigard.com>2018-12-04 16:04:14 +0100
commit745778256ced65415b04a9817fc49db70d4b6681 (patch)
tree184a3cd6c7d24ba94c5aa282b52a162a3b95d21c /server/helpers/image-utils.ts
parent2beb98952a4c5939f33ea2dc77f0bd053bffbb5a (diff)
downloadPeerTube-745778256ced65415b04a9817fc49db70d4b6681.tar.gz
PeerTube-745778256ced65415b04a9817fc49db70d4b6681.tar.zst
PeerTube-745778256ced65415b04a9817fc49db70d4b6681.zip
Fix thumbnail processing
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r--server/helpers/image-utils.ts14
1 files changed, 6 insertions, 8 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts
index da3285b13..e43ea3f1d 100644
--- a/server/helpers/image-utils.ts
+++ b/server/helpers/image-utils.ts
@@ -1,6 +1,7 @@
1import 'multer' 1import 'multer'
2import * as sharp from 'sharp' 2import * as sharp from 'sharp'
3import { move, remove } from 'fs-extra' 3import { readFile, remove } from 'fs-extra'
4import { logger } from './logger'
4 5
5async function processImage ( 6async function processImage (
6 physicalFile: { path: string }, 7 physicalFile: { path: string },
@@ -11,14 +12,11 @@ async function processImage (
11 throw new Error('Sharp needs an input path different that the output path.') 12 throw new Error('Sharp needs an input path different that the output path.')
12 } 13 }
13 14
14 const sharpInstance = sharp(physicalFile.path) 15 logger.debug('Processing image %s to %s.', physicalFile.path, destination)
15 const metadata = await sharpInstance.metadata()
16 16
17 // No need to resize 17 // Avoid sharp cache
18 if (metadata.width === newSize.width && metadata.height === newSize.height) { 18 const buf = await readFile(physicalFile.path)
19 await move(physicalFile.path, destination, { overwrite: true }) 19 const sharpInstance = sharp(buf)
20 return
21 }
22 20
23 await remove(destination) 21 await remove(destination)
24 22