Skip to content

Commit

Permalink
Use nested lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
ledyba committed May 10, 2022
1 parent a59c86c commit 2b9d911
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions server/src/lib/media/Convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ import path from 'node:path';
export async function resizeImage(src: string, dst: string, maxSize: number) {
// https://legacy.imagemagick.org/Usage/resize/
// https://blog.utgw.net/entry/2019/11/09/191158
let r;
switch(path.extname(src).toLocaleLowerCase()) {
case '.gif':
r = await spawn('magick', [
'convert',
src,
'-coalesce',
'-layers', 'optimize',
'-resize', `${maxSize}x${maxSize}`,
dst
]);
break;
default:
r = await spawn('magick', [
'convert',
src,
'-resize', `${maxSize}x${maxSize}`,
dst
]);
break;
}
const r = await (async()=>{
switch(path.extname(src).toLocaleLowerCase()) {
case '.gif':
return await spawn('magick', [
'convert',
src,
'-coalesce',
'-layers', 'optimize',
'-resize', `${maxSize}x${maxSize}`,
dst
]);
default:
return await spawn('magick', [
'convert',
src,
'-resize', `${maxSize}x${maxSize}`,
dst
]);
}
})();
if(r.status !== 0) {
throw new Error(`Failed to convert: ${r.stderr}`);
}
Expand Down

0 comments on commit 2b9d911

Please sign in to comment.