You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
616 B
TypeScript
20 lines
616 B
TypeScript
import sharp from "sharp"
|
|
import path from "path"
|
|
|
|
const resizeImg = async (width: number, height: number, fileName: string): Promise<string> => {
|
|
// output file for resized img
|
|
let inputimgPath: string = path.resolve("images/full", `${fileName}.jpg`);
|
|
let outputImg: string = path.resolve("images/thumb", `${fileName}.jpg`);
|
|
await sharp(path.resolve(inputimgPath))
|
|
.resize(width, height)
|
|
.toFormat("jpeg")
|
|
.jpeg({
|
|
quality: 100,
|
|
mozjpeg: true
|
|
})
|
|
.toFile(path.resolve(outputImg))
|
|
|
|
return outputImg
|
|
}
|
|
|
|
export default resizeImg |