diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-01 08:50:28 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-03-01 13:37:40 +0100 |
commit | 7bde625050cb661f51db20992f9f3912a582fcee (patch) | |
tree | 974bbb37e4e435dd5df0fbd1253ed300c12b85db /server/helpers/image-utils.ts | |
parent | 8d07888728bc5aabc7d0cd6211bc49fc45fd0353 (diff) | |
download | PeerTube-7bde625050cb661f51db20992f9f3912a582fcee.tar.gz PeerTube-7bde625050cb661f51db20992f9f3912a582fcee.tar.zst PeerTube-7bde625050cb661f51db20992f9f3912a582fcee.zip |
Fill width of local avatars
Diffstat (limited to 'server/helpers/image-utils.ts')
-rw-r--r-- | server/helpers/image-utils.ts | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index 6e4a2b000..9d0c09051 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { copy, readFile, remove, rename } from 'fs-extra' | 1 | import { copy, readFile, remove, rename } from 'fs-extra' |
2 | import Jimp, { read } from 'jimp' | 2 | import Jimp, { read as jimpRead } from 'jimp' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { getLowercaseExtension } from '@shared/core-utils' | 4 | import { getLowercaseExtension } from '@shared/core-utils' |
5 | import { buildUUID } from '@shared/extra-utils' | 5 | import { buildUUID } from '@shared/extra-utils' |
@@ -56,12 +56,26 @@ async function generateImageFromVideoFile (fromPath: string, folder: string, ima | |||
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | async function getImageSize (path: string) { | ||
60 | const inputBuffer = await readFile(path) | ||
61 | |||
62 | const image = await jimpRead(inputBuffer) | ||
63 | |||
64 | return { | ||
65 | width: image.getWidth(), | ||
66 | height: image.getHeight() | ||
67 | } | ||
68 | } | ||
69 | |||
59 | // --------------------------------------------------------------------------- | 70 | // --------------------------------------------------------------------------- |
60 | 71 | ||
61 | export { | 72 | export { |
62 | generateImageFilename, | 73 | generateImageFilename, |
63 | generateImageFromVideoFile, | 74 | generateImageFromVideoFile, |
64 | processImage | 75 | |
76 | processImage, | ||
77 | |||
78 | getImageSize | ||
65 | } | 79 | } |
66 | 80 | ||
67 | // --------------------------------------------------------------------------- | 81 | // --------------------------------------------------------------------------- |
@@ -71,7 +85,7 @@ async function jimpProcessor (path: string, destination: string, newSize: { widt | |||
71 | const inputBuffer = await readFile(path) | 85 | const inputBuffer = await readFile(path) |
72 | 86 | ||
73 | try { | 87 | try { |
74 | sourceImage = await read(inputBuffer) | 88 | sourceImage = await jimpRead(inputBuffer) |
75 | } catch (err) { | 89 | } catch (err) { |
76 | logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err }) | 90 | logger.debug('Cannot read %s with jimp. Try to convert the image using ffmpeg first.', path, { err }) |
77 | 91 | ||
@@ -79,7 +93,7 @@ async function jimpProcessor (path: string, destination: string, newSize: { widt | |||
79 | await convertWebPToJPG(path, newName) | 93 | await convertWebPToJPG(path, newName) |
80 | await rename(newName, path) | 94 | await rename(newName, path) |
81 | 95 | ||
82 | sourceImage = await read(path) | 96 | sourceImage = await jimpRead(path) |
83 | } | 97 | } |
84 | 98 | ||
85 | await remove(destination) | 99 | await remove(destination) |